T
TanStack2y ago
ugly-tan

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
adverse-sapphire
adverse-sapphire2y ago
Can you show a reproduction of this please by forking one of the examples. Thanks 🙏
ugly-tan
ugly-tanOP2y ago
Oh no I just realized what I did........ I'm freezing the context on the parent that's why
adverse-sapphire
adverse-sapphire2y ago
huh what's that?
ugly-tan
ugly-tanOP2y 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?