Created
October 23, 2018 01:00
-
-
Save martinseanhunt/856105543a9ed15129896e0a6fb08313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Mutation | |
mutation={CREATE_LIST_ITEM} | |
variables={{ title: this.state.title }} | |
// Refetch pagination data on creating an item to update item | |
// & page counts. The Query is being imported from ./Pagination | |
refetchQueries={[{ query: LIST_ITEMS_CONNECTION_QUERY }]} | |
// Call our helper function on update (it will be passed the chache) | |
update={deleteListItemsFromCache} | |
onCompleted={() => Router.push('/') } | |
> | |
{(createListItem, {error, loading}) => { | |
if(loading) return <p>Loading...</p> | |
if(error) return alert(error) | |
return ( | |
<> | |
<label htmlFor="title"> | |
Title: | |
<input | |
id="title" | |
name="title" | |
onChange={e => this.setState({ title: e.target.value })} | |
/> | |
</label> | |
<button onClick={createListItem}>Create Item</button> | |
</> | |
) | |
}} | |
</Mutation> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment