Recoil: Support "context bridging"

Created on 22 May 2020  路  7Comments  路  Source: facebookexperimental/Recoil

Since Recoil relies on the context to propagate and store its state, it would be nice to have the ability to bridge this context, if it isn't propagated to all nodes in the tree.

Unfortunately, this is the case with ReactART (and friends) and the only proposed solution (for now) is to bridge the context using a "Consumer" with another "Provider" directly below it. See https://github.com/facebook/react/issues/13336 and in particular this comment: https://github.com/facebook/react/issues/13336#issuecomment-414709155. Recoil does not provide this, AFAICS.

Would it be possible to either:

  • Provide a RecoilConsumer that does this or
  • Get access to the underlying context?
enhancement

Most helpful comment

Was just wondering if instead of exposing AppContext (I mean, if there are really concern on this) exposing and ContextBridging component like @inlet suggests here would be a viable alternative... 馃

All 7 comments

Hi @jonas-jonas. Interesting issue, first time I've come across the ideas around 'context bridging" so have learnt something new 馃榾.

I might be missing something, but with my limited understanding of how Recoil works it doesn't sound like it would be easy/safe to share a context between two different React renderers.
It might be possible / easier to keep two Recoil stores in sync using the unstable useTransactionSubscription API.

I'm the author of react-pixi and I'd love to use Recoil for state management.

Unfortunately Contexts don't propagate between renderers, Context bridging is a good way to make this possible.

I'd love to see Recoil's AppContext exported as well.

I wonder if this is something that could be done with the new Snapshot API for sharing state across <RecoilRoot>s... What are the requirements for what you are trying to accomplish?

In case of react-native-navigation, that can be have many react roots. It's need to the way to share state across <RecoilRoot>.

Was just wondering if instead of exposing AppContext (I mean, if there are really concern on this) exposing and ContextBridging component like @inlet suggests here would be a viable alternative... 馃

Added a comment to #298 to discuss a proposed approach.

Documented new #516 API in #483

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tklepzig picture tklepzig  路  3Comments

yuantongkang picture yuantongkang  路  3Comments

polemius picture polemius  路  3Comments

ymolists picture ymolists  路  3Comments

atanasster picture atanasster  路  3Comments