DEV Community

DEBOS DAS
DEBOS DAS

Posted on

sonner for toast

npm install sonner
Enter fullscreen mode Exit fullscreen mode

https://sonner.emilkowal.ski/
Call main.tsx

import { Provider } from 'react-redux';
import { persistor, store } from './redux/features/store.ts';
import { PersistGate } from 'redux-persist/integration/react';
import { Toaster } from 'sonner';

ReactDOM.createRoot(document.getElementById('root')!).render(
    <React.StrictMode>
        <Provider store={store}>
            <PersistGate loading={null} persistor={persistor}>
                <RouterProvider router={router}></RouterProvider>
            </PersistGate>{' '}
        </Provider>
        <Toaster />
    </React.StrictMode>
);

Enter fullscreen mode Exit fullscreen mode
**Then use onSbumit login.tsx**
Enter fullscreen mode Exit fullscreen mode
const onSubmit = async (data) => {
        toast.loading('Logging in');
        const userInfo = {
            id: data.id,
            password: data.password,
        };
        const res = await login(userInfo).unwrap();
        const user = verifyToken(res.data.accessToken);
        dispatch(setUser({ user: user, token: res.data.accessToken }));
        navigate(`/${user.role}/dashboard`);
    };

Enter fullscreen mode Exit fullscreen mode

Top comments (0)