mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
4466ba436b
## 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
75 lines
1.7 KiB
JavaScript
75 lines
1.7 KiB
JavaScript
import { gql, useMutation } from "@apollo/client";
|
|
|
|
const CREATE_POST_MUTATION = gql`
|
|
mutation createPost($title: String!, $url: String!) {
|
|
createPost(title: $title, url: $url) {
|
|
id
|
|
title
|
|
votes
|
|
url
|
|
createdAt
|
|
}
|
|
}
|
|
`;
|
|
|
|
const Submit = () => {
|
|
const [createPost, { loading }] = useMutation(CREATE_POST_MUTATION);
|
|
|
|
const handleSubmit = (event) => {
|
|
event.preventDefault();
|
|
const form = event.target;
|
|
const formData = new window.FormData(form);
|
|
const title = formData.get("title");
|
|
const url = formData.get("url");
|
|
form.reset();
|
|
|
|
createPost({
|
|
variables: { title, url },
|
|
update: (cache, { data: { createPost } }) => {
|
|
cache.modify({
|
|
fields: {
|
|
allPosts(existingPosts = []) {
|
|
const newPostRef = cache.writeFragment({
|
|
data: createPost,
|
|
fragment: gql`
|
|
fragment NewPost on allPosts {
|
|
id
|
|
type
|
|
}
|
|
`,
|
|
});
|
|
return [newPostRef, ...existingPosts];
|
|
},
|
|
},
|
|
});
|
|
},
|
|
});
|
|
};
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
<h1>Submit</h1>
|
|
<input placeholder="title" name="title" type="text" required />
|
|
<input placeholder="url" name="url" type="url" required />
|
|
<button type="submit" disabled={loading}>
|
|
Submit
|
|
</button>
|
|
<style jsx>{`
|
|
form {
|
|
padding-bottom: 20px;
|
|
margin-bottom: 20px;
|
|
}
|
|
h1 {
|
|
font-size: 20px;
|
|
}
|
|
input {
|
|
display: block;
|
|
margin-bottom: 10px;
|
|
}
|
|
`}</style>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
export default Submit;
|