I am using react hooks and redux. I have wrapped the App
component with BrowserRouter
:
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
and in the App
component, I am using useHistory
hook to get the history
object:
const history = useHistory();
useEffect(()=>{
history.listen((location, action) => {
// clear alert on location change
dispatch(alertActions.clear());
});
But i want to access the history
object in my action creator file used for login, so that i can do this after login:
history.push('/');
How do I achieve this? do I have to use Router
instead of BrowserRouter
?
Edit:
I had to use Router
, instead of BrowserRouter
, and it is working now.