lagunovsky / redux-react-router

A Redux binding for React Router v6
MIT License
73 stars 9 forks source link

Can't call setState on a component that is not yet mounted. #3

Closed burnmaniac closed 2 years ago

burnmaniac commented 2 years ago

Seems like there is an issue with ReduxRouter component.

When navigating between two routes, on the first location change, there is an error in the console saying:

Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the ReduxRouter component.

I might point you in the right direction or completely in the wrong direction, but when I disable StrictMode, the error is gone. It would be nice to work with StrictMode enabled as well, tho.

EDIT: I just had a look at the ReduxRouter component implementation. There is a setState call in the constructor. I believe moving the this.removeHistoryListener listener to componentDidMount would remove the error, but I'm not sure if that's the right solution.