First of all. Very well written question. Thanks: -)
The general model used in the React and Relay world is that we have a parent component that works with the thin view controller, retrieves data using Relay, and passes its state different parts as props to different child components as needed. Detailed components that accept data as props are usually dumb and simply display the transmitted data.
In your case, ChildComponent itself edits the data. It gets the initial details data from its parent HelloApp component. However, when we edit any of the details fields in the user interface, the values โโobtained using Relay and the values โโin the user interface do not match. When creating a Relay container for a child component, if we include fragments and fields, we declare that the relay will retrieve this data. Now , if we want to change the data of the child components (details) ourselves, we just skip this fragment in the Relay container. props passed by the parent component will only be used for the initialState child component.
The necessary changes are in the HelloApp container. Details fields are moved from a child to a parent.
HelloApp = Relay.createContainer(HelloApp, { fragments: { person: () => Relay.QL` fragment on Person { name, details { hairColor, nickName } } `, } });
BUT I still feel uncomfortable with the above solution. Because this clearly shows that the parent needs to know the details fields that are actually used in the child components.
source share