I have the following code
const Companies = () => {
const [company, setCompany] = useState(plainCompanyObj);
const [companiesData, setCompaniesData] = useState([]);
useEffect(() => {
Call<any, any>({
url:
_baseApiUrl +
"-------api goes here --------",
method: "GET",
data: null,
success: (companies) => {
setCompaniesData(companies.companies);
},
authorization: sessionStorage.getItem("accessToken"),
});
}, []);
return (
//return JSX
);
};
I get the following error: 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 a useEffect cleanup function.
Also just to clarify the Call
tag is a method imported by axios
that I use for URL error handler etc. The problem as the error suggests is in the useEffect
section.
<Companies />
component. Maybe in there, you have some logic that unmounts your<Companies />
component prematurely. – Nemanja Lazarevic<Box> <Companies /> </Box>
– Gerald Yllireturn () => {console.log("Component Unmounded")}
at the bottom of youruseEffect
. If after refresh you see this log, means you have to search for the culprit somewhere up in the component's tree. – Nemanja Lazarevic