Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React, { Component } from 'react';
import { Mutation } from 'urql';
const addTodo = `
mutation AddTodo($text: String!) {
addTodo(text: $text) {
id
text
}
}
`;
class TodoForm extends Component {
state = {
error: null
};
add = () => {
this.props.addTodo({ text: 'something!' })
.catch(error => {
this.setState({ error });
});
};
render() {
if (this.state.error) {
return 'Oh no!';
}
return <button onClick={this.add}>Add something!</button>
}
}
const WithMutation = () => (
<Mutation query={addTodo}>
{({ executeMutation }) => <TodoForm addTodo={executeMutation} />
</Mutation>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.