rsnext/examples/with-apollo-and-redux/components/PostUpvoter.js
Steven 4466ba436b
chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00

65 lines
1.3 KiB
JavaScript

import { gql, useMutation } from "@apollo/client";
import PropTypes from "prop-types";
const VOTE_POST = gql`
mutation votePost($id: String!) {
votePost(id: $id) {
__typename
id
votes
}
}
`;
const PostUpvoter = ({ votes, id }) => {
const [votePost] = useMutation(VOTE_POST);
const upvotePost = () => {
votePost({
variables: {
id,
},
optimisticResponse: {
__typename: "Mutation",
updatePost: {
__typename: "Post",
id,
votes: votes + 1,
},
},
});
};
return (
<button onClick={() => upvotePost()}>
{votes}
<style jsx>{`
button {
background-color: transparent;
border: 1px solid #e4e4e4;
color: #000;
}
button:active {
background-color: transparent;
}
button:before {
align-self: center;
border-color: transparent transparent #000000 transparent;
border-style: solid;
border-width: 0 4px 6px 4px;
content: "";
height: 0;
margin-right: 5px;
width: 0;
}
`}</style>
</button>
);
};
PostUpvoter.propTypes = {
id: PropTypes.string.isRequired,
votes: PropTypes.number.isRequired,
};
export default PostUpvoter;