npm install sonner
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>
);
**Then use onSbumit login.tsx**
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`);
};
Top comments (0)