Skip to content

Commit

Permalink
Use refetchQueries to update data after a delete
Browse files Browse the repository at this point in the history
  • Loading branch information
cannikin committed Apr 13, 2020
1 parent 7097b2d commit 81e93b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ const timeTag = (datetime) => {
}

const PostsList = ({ posts }) => {
const [deletePost] = useMutation(DELETE_POST_MUTATION, {
onCompleted: () => {
location.reload()
},
})
const [deletePost] = useMutation(DELETE_POST_MUTATION)

const onDeleteClick = (id) => {
if (confirm('Are you sure you want to delete post ' + id + '?')) {
deletePost({ variables: { id } })
deletePost({ variables: { id }, refetchQueries: ['POSTS'] })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ const timeTag = (datetime) => {
}

const ${pluralPascalName}List = ({ ${pluralCamelName} }) => {
const [delete${singularPascalName}] = useMutation(DELETE_POST_MUTATION, {
onCompleted: () => {
location.reload()
},
})
const [delete${singularPascalName}] = useMutation(DELETE_POST_MUTATION)

const onDeleteClick = (id) => {
if (confirm('Are you sure you want to delete ${singularCamelName} ' + id + '?')) {
delete${singularPascalName}({ variables: { id } })
delete${singularPascalName}({ variables: { id }, refetchQueries: ['POSTS'] })
}
}

Expand Down

0 comments on commit 81e93b2

Please sign in to comment.