How to use the graphql-hooks.useMutation function in graphql-hooks

To help you get started, weโ€™ve selected a few graphql-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / next.js / examples / with-graphql-hooks / components / post-upvoter.js View on Github external
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 &amp;&amp; onUpdate(result)
        } catch (e) {
          console.error('error upvoting post', e)
        }</button>
github zeit / next.js / examples / with-graphql-hooks / components / submit.js View on Github external
export default function Submit({ onSubmission }) {
  const [createPost, state] = useMutation(CREATE_POST)

  return (
    <form> handleSubmit(event, onSubmission, createPost)}&gt;
      <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>
github nearform / graphql-hooks / examples / typescript / src / App.tsx View on Github external
function AddPost({ onSuccess }: { onSuccess: () =&gt; 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 &amp;&amp; onSuccess()
  }

  return (
    <form>
      <label>Title:</label>
      <input required="" value="{title}"> setTitle(e.currentTarget.value)}
      /&gt;</form>
github nearform / graphql-hooks / examples / create-react-app / src / components / CreatePost.js View on Github external
export default function CreatePost({ onSuccess }) {
  const [createPost, { loading, error }] = useMutation(createPostMutation)

  async function handleSubmit({ title, url }) {
    await createPost({ variables: { title, url } })
    onSuccess &amp;&amp; onSuccess()
  }

  return (
    
  )
}
github nearform / graphql-hooks / examples / fastify-ssr / src / app / pages / HomePage.js View on Github external
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()
  }

graphql-hooks

Graphql Hooks

Apache-2.0
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis