mutation-cache-update
perform Apollo client add and delete mutation with local cache update using simple react hook
mutation-cache-update
Very simple and small hook that can be used for updating local the cache while performing Apollo client add and delete mutation.
Install
npm install --save mutation-cache-update
Usage
import React from 'react'import useAddMutation Loading from 'mutation-cache-update'import gql from 'apollo-boost'; const GET_TODOS = gql` query GetTodos { todos }`; const ADD_TODO = gql` mutation AddTodo($type: String!) { addTodo(type: $type) { id type } }`; const App = const addTodo error loading data = ifloading return <Loading> let input return <div> <div> <form = > <input = /> <button ='submit'>Add Todo</button> </form> </div> </div>
to perform delete mutation
import useDeleteMutation Loading from 'mutation-cache-update'const deleteTodo error loading data =
Loading indicator spinner
ifloading return <Loading/>
Contribution
Any suggestion is welcome.
License
MIT © ephremdeme
This hook is created using create-react-hook.