T
TanStack16mo ago
passive-yellow

cannot use useParams data in a useEffect hook!

When I use const {channelId} = Route.useParams() It seems that channelId does not update when I listen to it in a useEffect hook
const { channelId } = Route.useParams();

useEffect(() => {
// This does not run when I navigate to a route with different param!
// example: /channels/123 -> /channels/321
console.log(channelId);
}, [channelId]);
const { channelId } = Route.useParams();

useEffect(() => {
// This does not run when I navigate to a route with different param!
// example: /channels/123 -> /channels/321
console.log(channelId);
}, [channelId]);
4 Replies
fair-rose
fair-rose16mo ago
Can you show a reproduction of this please by forking one of the examples. Thanks 🙏
passive-yellow
passive-yellowOP16mo ago
Oh no I just realized what I did........ I'm freezing the context on the parent that's why
fair-rose
fair-rose16mo ago
huh what's that?
passive-yellow
passive-yellowOP16mo ago
Well I'm animating my routes which requires freezing the context so that <Outlet/> doesn't change. It's a whole complicated system I came up with but I just fixed my issue!

Did you find this page helpful?