Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function PostUpvoter({ votes, id, onUpdate }) {
const [updatePost] = useMutation(UPDATE_POST)
return (
<button> {
try {
const result = await updatePost({
variables: {
id,
votes: votes + 1,
},
})
onUpdate && onUpdate(result)
} catch (e) {
console.error('error upvoting post', e)
}</button>
export default function Submit({ onSubmission }) {
const [createPost, state] = useMutation(CREATE_POST)
return (
<form> handleSubmit(event, onSubmission, createPost)}>
<h1>Submit</h1>
<input required="" type="text" placeholder="title">
<input required="" type="url" name="url" placeholder="url">
<button type="submit">{state.loading ? 'Loading...' : 'Submit'}</button>
<style>{`
form {
border-bottom: 1px solid #ececec;
padding-bottom: 20px;
margin-bottom: 20px;
}
h1 {
font-size: 20px;
}</style></form>
function AddPost({ onSuccess }: { onSuccess: () => void }) {
const [title, setTitle] = useState('')
const [url, setUrl] = useState('')
const [createPost, { loading, error }] = useMutation(createPostMutation)
async function handleSubmit(e: any) {
e.preventDefault()
await createPost({ variables: { title, url } })
onSuccess && onSuccess()
}
return (
<form>
<label>Title:</label>
<input required="" value="{title}"> setTitle(e.currentTarget.value)}
/></form>
export default function CreatePost({ onSuccess }) {
const [createPost, { loading, error }] = useMutation(createPostMutation)
async function handleSubmit({ title, url }) {
await createPost({ variables: { title, url } })
onSuccess && onSuccess()
}
return (
)
}
function HomePage() {
const [name, setName] = React.useState('')
const { loading, data, error, refetch: refetchUsers } = useQuery(
HOMEPAGE_QUERY
)
const [createUser] = useMutation(CREATE_USER_MUTATION)
const [getFirstUser, { data: firstUserData }] = useManualQuery(
GET_FIRST_USER_QUERY,
{
fetchOptionsOverrides: {
method: 'GET'
}
}
)
async function createNewUser() {
await createUser({ variables: { name } })
setName('')
refetchUsers()
}