Skip to content

Re-initializing state between token routes? #1388

Answered by SeanCassiere
rfedoruk asked this question in Q&A
Discussion options

You must be logged in to vote

I'd probably stay away from the useEffect and use key to trigger the re-render.

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} />;
  },
});

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rfedoruk
Comment options

@VladKopylov
Comment options

@SeanCassiere
Comment options

Answer selected by rfedoruk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants