I'm having a problem with an application that uses the Provider approach to update the state through the whole app. The browser's console throws a warning because a react component that is redirecting to another one using react-router-dom on a click event, is also dispatching an action while the second one is already mounted.
index.js:1 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
This is the code.The main components are Details and Results, when I switch from one to another in the browser the warning shows up.
https://github.com/juampablotoledo/prueba-redux.git
This is my index.js
import React from "react";
import ReactDom from "react-dom";
import { Provider } from "react-redux";
import { BrowserRouter, Route, Redirect, Switch } from "react-router-dom";
import Results from "./components/results";
import Details from "./components/details";
import store from "./redux/store";
const Root = (
<Provider store={store}>
<BrowserRouter>
<Switch>
<Route path="/results">
<Results />
</Route>
<Route path="/details/:itemId">
<Details />
</Route>
<Redirect from="/" to="/results" />
</Switch>
</BrowserRouter>
</Provider>
);
ReactDom.render(Root, document.getElementById("root"));
I've been reading several posts about unsubscribing actions to prevent issues like this, but I don't know if the Provider component can live alongside with subscribe.