Conditional useRecoilValue usage
See original GitHub issueHow can I conditionally observe recoil state changes? I don’t see that this is currently possible. This is also not easy to do in MobX but it’s possible.
I’d like to be able to pass a falsy value to useRecoilValue
isObserving = false;
const names = useRecoilValue(isObserving && namesState);
See my MobX question: https://github.com/mobxjs/mobx-react/issues/864
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
useRecoilValue(state) | Recoil
Returns the value of the given Recoil state. This hook will subscribe the component to re-render if there are changing in the Recoil...
Read more >React Recoil useRecoilValue is returning an empty atom
Try change this part of code in Collage.js const adog = useRecoilValue(activeDogAtom); var dog = ""; if(adog === ''){. to this:
Read more >Get started with Recoil by building a Fantasy app in React ...
To consume this data, we will use the useRecoilValue() function ... Also, by adding this conditional style { backgroundColor: isSelected ?
Read more >Recoil.js & simple global state
Use this hook when you need to read the value of an atom but not write to it. const myData = useRecoilValue(dataAtom);. Selector....
Read more >Build your own Recoil - ITNEXT
With the help of useRecoilValue or useRecoilState hooks it is possible to use atoms in a React component: function TextInput() {
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Internally there is another hook we use for conditional access:
This allows conditional lookups, getting values in loops, after components short-circuit returns, &c. We’re not super keen on the interface, though, it is unstable and will change. I’m hoping to come up with a safer/cleaner approach to publish.
Hi @AjaxSolutions.
Yep that’s the way. In Recoil/utils there is a useful helper for this pattern
constSelector
https://github.com/facebookexperimental/Recoil/blob/c38012d92a292a4a867163cf7b14cfb3debddf01/src/recoil_values/Recoil_const.js#L30-L32Can use it like this: