Multiple Relay Containers And Variables Communication
I'm trying to change variables of a Relay Container from another Relay Container. They don't have a parent-child relation and both are in two separated Root Containers.
Container = Relay.createContainer(Component, {
initialVariables: {
value: 10
},
fragments: {
fragmentOne: () => Relay.QL`
fragment on Score {
score(value: $value)
}`
}
});
Assuming the scenario I described: Which is the best way to change $value variable from the Container above, from another Container? There is a way to do only with Relay or I need Redux (or Reflux) to make this work?
Thanks!
Answer
I would reconsider the design of your app. The purpose of a root container is to sit at the top and hold your app together.
https://facebook.github.io/relay/docs/guides-root-container.html
Once you have two root containers, you are building two apps. If your app really needs to be this way, you may not be out of luck. Multiple apps usually communicate with each-other via an API. With Relay, that API speaks graphql. Normally you would need to go to a server to communicate, but since your apps live on the same page you could circumvent the server with a local graphql api.
https://github.com/relay-tools/relay-local-schema
Use this solution with caution though, as mentioned in the readme.
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?