Setting state in the Query component of react-apollo. Whatever component needs this data as state should be rendered inside the Query component, and then have the data passed down to it as a prop.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class MyComponent extends React.Component { constructor (props) { this.state = { title: props.post.title } } } <Query query={POST_QUERY} variables={{ id: this.props.match.params.id }}> {({ data, loading, error }) => { <MyComponent post={data.post}/> }} </Query> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.