Skip to content

Why do I need to wrap my react components with observer when using React's useState or useMemo? #3570

Answered by kubk
koloer-blus asked this question in Q&A
Discussion options

You must be logged in to vote

If you remove observer the component stops updating (unless parent component is updating, which trigger the update for children). useState is used here only to keep value between component rerenders. The value that holds useState is never updated. Notice that you have const [timer] = useState(...), not const [timer, setState] = useState(...). Only Mobx is involved here to update the component

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@koloer-blus
Comment options

Answer selected by koloer-blus
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