Can an atom's value be changed from a non-react environment?
See original GitHub issueRecently I came across the use case like a pure js file Realtime.service.js
is making a connection with the WebSocket server and streaming realtime data to UI (need to feed multiple React’s components with a chunk of data coming from realtime WS).
Now if Recoil’s atom state can be changed directly from Realtime.service.js
(which is not a React component but js service) with realtime steam then all the components connected with the relative atoms will be updated on realtime data streaming.
Is that a valid use case? Right now I’ve seen that Atom’s state only get/set default-value by React’s hook.
In redux it is possible, we can update the store from any js file (non-react env). and the react-redux
bridge auto handles the changes to connected components. Now we’re moving from Redux to Recoil, we’re having this roadblock.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top GitHub Comments
You could hack it
I’m hopeful that this API #380 could help with this use case.