Skip to content

Create an atom that always reflects an up-to-date external value #1088

Answered by drarmstr
papermana asked this question in Q&A
Discussion options

You must be logged in to vote

Async data could be used as an input to the data-flow graph via a selector. You could also use Atom Effects to subscribe to some external value change and update an atom. In either case you can have derived selectors which will be updated automatically. However, if your external value is obtained via a React hook, then neither of these approaches will work as you cannot use hooks from within a selector or effect. In that case useEffect() can be used by some component just for the purposes of keeping the external state in sync with an atom. Note that we are currently working on an optimization that will issue re-renders earlier for state updates which may possibly help reducing your latenc…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@papermana
Comment options

@drarmstr
Comment options

Answer selected by papermana
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