I am looking for good syntax to pass a variable from a parent container to a child container.
Say I have these routes, with a global list of widgets on / and specific lists of widgets on /widgets/:WidgetListID .
Note. I am using relay-router-relay
<Route path='/' component={Layout} > <IndexRoute component={WidgetListContainer} queries={ViewerQueries} /> <Route path='/widgets/:WidgetListID' component={WidgetListContainer} queries={ViewerQueries} /> </Route>
This is the same <WidgetList/> component displayed inside the <WidgetListContainer/> inside <Layout/> , and this is how I try to pass the WidgetListID variable:
Layout.js
class Layout extends React.Component { render() { return ( <div> ... {children} ... </div> ); } }
WidgetListContainer.js
class WidgetListContainer extends React.Component { render () { return ( <div> ... <WidgetList viewer={viewer} /> </div> ) } } export default Relay.createContainer(WidgetListContainer, { initialVariables: { WidgetListID: null }, fragments: { viewer: ($WidgetListID) => Relay.QL` fragment on User { ${WidgetList.getFragment('viewer', $WidgetListID)} } `, }, })
WidgetList.js
class WidgetList extends React.Component { render () { return ( <div> <ul> {viewer.widgets.edges.map(edge => <li key={edge.node.id}>{edge.node.widget.name}</li> )} </ul> </div> ) } } export default Relay.createContainer(WidgetList, { initialVariables: { WidgetListID: null }, fragments: { viewer: () => Relay.QL` fragment on User { widgets(first: 10, WidgetListID:$WidgetListID) { edges { node { id, name } } } } `, }, })
I have no problem setting the WidgetListID variable directly inside the WidgetList relay container, it works fine, but as soon as I try to transfer it from the WidgetListContainer relay container, I have an empty data object {__dataID__: "VXNlcjo="} . Although the variable is well printed in my getWidget () function. So something is not working at some point, but I canβt understand what?
What would be the good syntax for passing the WidgetListID variable from the parent container to the child container?