silverwolf-x's picture
download
raw
1.76 kB
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;

Xet Storage Details

Size:
1.76 kB
·
Xet hash:
c66d31d737fdd8788f1558639e1ee2b5b27575cbd4a7cc7c3e4b5eb8eff90018

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.