b3a631305d
Fixes #20474 * Switch API url to working URL used in apollo example * Update deps * Move styled jsx out of the way to avoid demonstrating too many unfamiliar concepts at once dev, build and start work now.
37 lines
693 B
JavaScript
37 lines
693 B
JavaScript
import React from 'react'
|
|
import { useMutation } from 'graphql-hooks'
|
|
|
|
const UPDATE_POST = `
|
|
mutation votePost($id: String!) {
|
|
votePost(id: $id) {
|
|
id
|
|
votes
|
|
__typename
|
|
}
|
|
}
|
|
`
|
|
|
|
export default function PostUpvoter({ votes, id, onUpdate }) {
|
|
const [updatePost] = useMutation(UPDATE_POST)
|
|
|
|
return (
|
|
<button
|
|
className="upvote"
|
|
onClick={async () => {
|
|
try {
|
|
const result = await updatePost({
|
|
variables: {
|
|
id,
|
|
},
|
|
})
|
|
|
|
onUpdate && onUpdate(result)
|
|
} catch (e) {
|
|
console.error('error upvoting post', e)
|
|
}
|
|
}}
|
|
>
|
|
{votes}
|
|
</button>
|
|
)
|
|
}
|