Accidental state persistence across next dynamic routes?

Just noticed that /profile/[username].tsx persists useState() between different users in my app... My solution and the first stackoverflow answer I found is:
useEffect(() => {
setState(resetState) // When the dynamic route change reset the state
}, [dynamicRoute])
useEffect(() => {
setState(resetState) // When the dynamic route change reset the state
}, [dynamicRoute])
This works for me but it feels weird after avoiding useEffects before. Is there a better way to do this or is the useEffect as good as it gets?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server