I have a React function component (a route component) that should do something when it is unmounted (i.e. the user clicks the browser Back button) and contains the following relevant lines:
// ...
const params = useParams<ISomeInterfaceHere>();
// ...
// I verified that `data` below actually loads but it does not last until the component unmounts.
const { data, isLoading, isError } = useGetSomethingQuery(params.x, {
refetchOnMountOrArgChange: true,
});
// ...
useEffect(() => {
return () => {
// current state:
//
// isLoading === true
// isError === false
// data === undefined
};
}, []);
// ...
Does it have to do with the useParams
hook which is from the react-router
package? Is this a bug in RTKQ or, if not, what is the defined behavior? And, most importantly, how can I get the last defined value of data
just before the component unmounts?
There are no error messages.
Update 1
I use:
"react": "^16.14.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"@reduxjs/toolkit": "^1.6.0",
Update 2
I am sure that the params
are not getting updated, not even params.x
. I also upgraded to @reduxjs/toolkit
v1.6.1
and I have the same issue.
Update 3
A code sandbox with the isolated issue is here. It looks to me like it is a bug in RTKQ.
Update 4
I opened a GH bug report here.