Skip to content

Instantly share code, notes, and snippets.

@EddiG
Last active March 30, 2018 05:35
Show Gist options
  • Save EddiG/705d06d283689cdde107576660bb3dd2 to your computer and use it in GitHub Desktop.
Save EddiG/705d06d283689cdde107576660bb3dd2 to your computer and use it in GitHub Desktop.
That is how you can reuse the Mutation component from React Apollo client
const DeleteItemMutation = ({ id, render }) => (
  <Mutation mutation={DELETE_ITEM_MUTATION}>
    {mutate =>
      render({
        deleteItem: id => {
          mutate({
            variables: { id },
            // optimisticResponse
            // update
          });
        },
      })
    }
  </Mutation>
);

const Item = ({ id }) => (
  <DeleteItemMutation
    id={id}
    render={({ deleteItem }) => (
      <li>
        <button onClick={() => deleteItem()}>Delete</button>
      </li>
    )}
  />
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment