mutation on mount apollo client code example
Example: component did mount mutation graphql
import React from 'react';
import { Mutation } from 'react-apollo';
class DoMutation extends React.Component {
componentDidMount() {
const { mutate } = this.props;
mutate();
};
render() {
return null;
};
};
const MutationOnMount = ({ children, ...other }) => {
return (
<Mutation
{...other}
>
{(mutate, { data, loading, error }) => (
<React.Fragment>
<DoMutation mutate={mutate} />
{ children && children(mutate, { data, loading, error }) }
</React.Fragment>
)}
</Mutation>
)
};
export default MutationOnMount;