Skip to content

Re-execute atom whenever a component is mount #97

Answered by bowheart
Darksoulsong asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @Darksoulsong as you have it, I'd expect ttl: 0 to do the trick. But there are a few more factors to consider:

  • Is the modal component the only thing using this atom?
  • Does the modal component unmount when it's "destroyed" or is it only hidden (e.g. returning null when its open prop is false)?

If other components, atoms, or selectors use the fetchSomethingAtom, they may be preventing it from being destroyed. When the modal is closed, you can check the atom's dependents with ecosystem.viewGraph() to see if it's still in the graph and what dependents are keeping it there.

If the component doesn't actually unmount, its own useAtomValue call will maintain the dependency on the atom, preve…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Darksoulsong
Comment options

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