I have a parent component that requests data from the root like so:
export default createFragmentContainer(App, {
viewer: graphql`
fragment App_viewer on User {
id
email
name
}
`
})
Because I'm using React Router, the child routes are available through this component's this.props.children
. I'd like to pass the email
and name
of the viewer to this child by setting data requirements through fragments.
I was doing something like this:
const childrenWithProps = React.Children.map(
this.props.children, (child) => React.cloneElement(child, {viewer})
);
But that's really over-generalized for cases where all viewer
data is not necessary. Is there a simple way to have the child declare its data needs? Thanks!