简体   繁体   中英

Redux connect with Relay

How can I use redux connect with Relay.createContainer?

should I wrapper Relay.createContainer with redux or the other way?

or should I get redux state from context? what is the best approach?

if I get data from context how can I make the component rerender when redux state change?

My component needs to get data from redux and from relay

As far as I'm concerned, Relay + Redux are a great fit together--there is app level state that has nothing to do with server state, data, or caching... stuff like, "is a global modal active?". It took quite a bit of soul searching and experimenting to come to this conclusion.

What I believe works the best is to treat React + Redux as if it were the default way to build your application, then wrap Relay on top of that.

Relay.createContainer(
  connect(mapStateToProps)(BaseComponent), 
  {
    initialVariables: { ... },
    fragments: { ... },
  }
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM