I need help to share recoil root to other component and a way to get and set state outside of component #1839
-
Hello ! I want to share recoilroot to an other react dom render using Web components. And i want to know a way to access to state from outside recoilroot like i did with redux with creation store and storing it in variable. I don't know how to do it, if someone can help me with an example it's would be great |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Recoil state is coupled with the particular version of state being rendered for the host |
Beta Was this translation helpful? Give feedback.
-
Hello after a lot of search, i has seen some people using event emitter function with a lib like RxJS to update from outside a component is it a good way too ? |
Beta Was this translation helpful? Give feedback.
Recoil state is coupled with the particular version of state being rendered for the host
<RecoilRoot>
store, and isn't "global" per-se. That said, from a component in that React component tree you can use something likeuseRecoilCallback()
to create accessors and setters for reading and updating Recoil state from outside of rendering functions. There are also third-party libraries likerecoil-nexus
, I think, that provide this pattern.