Constimport { gql, useDataClientMutation } from '\@twilio/flex-sdk/data-client';
const ADD_TODO = gql`
mutation AddTodo($type: String!) {
addTodo(type: $type) {
id
type
}
}
`;
function AddTodo() {
let input;
const [addTodo, { data }] = useDataClientMutation(ADD_TODO);
return (
<div>
<form
onSubmit={(e) => {
e.preventDefault();
addTodo({ variables: { type: input.value } });
input.value = '';
}}
>
<input
ref={(node) => {
input = node;
}}
/>
<button type="submit">Add Task</button>
</form>
</div>
);
}
A hook for executing mutations in an Apollo application. Refer to the Mutations section for a more in-depth overview of
useMutation.