Re-initializing state between token routes? #1388
-
So I'm trying to see if this is the best way to do this. I am using file based routing, and I have a route that is say: $postId.tsx The way around this that I found is using a useEffect with the dependency array of Route Param. Any help would be appreciated, thank you! also here is a short snippet:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'd probably stay away from the export const Route = createFileRoute('/posts/$postId')({
loader: async ({ params: { postId } }) => fetchPost(postId),
errorComponent: PostErrorComponent as any,
notFoundComponent: () => {
return <p>Post not found</p>;
},
component: () => {
const { postId } = Route.useParams();
return <PostComponent key={postId} />;
},
}); |
Beta Was this translation helpful? Give feedback.
I'd probably stay away from the
useEffect
and usekey
to trigger the re-render.