I am trying to dispatch a redux action in the componentDidUpdate lifecycle method, however it results in an infinite loop that causes the application to crash. Here's the code I currently have:
componentDidUpdate(prevProps, prevState) {
const { dispatch, sockOpen, user } = this.props;
if (
navigator.onLine &&
user &&
(sockOpen !== prevProps.sockOpen || sockOpen)
) {
dispatch(pollStartAction());
this._checkSessionIntervalId = setInterval(
this.checkActiveSessions,
5000
);
}
}
Is this the right way of doing this or is there a better of writing this that wouldn't result in an infinite render loop. Thanks.