create user using react hook apollo code example
Example 1: useLazyQuery
import React, { useState } from 'react';
import { useLazyQuery } from '@apollo/client';
function DelayedQuery() {
const [dog, setDog] = useState(null);
const [getDog, { loading, data }] = useLazyQuery(GET_DOG_PHOTO);
if (loading) return Loading ...
;
if (data && data.dog) {
setDog(data.dog);
}
return (
{dog && }
);
}
Example 2: apollo graphql mutation hook
const UPDATE_TODO = gql`
mutation UpdateTodo($id: String!, $type: String!) {
updateTodo(id: $id, type: $type) {
id
type
}
}
`;
function Todos() {
const { loading, error, data } = useQuery(GET_TODOS);
const [updateTodo] = useMutation(UPDATE_TODO);
if (loading) return Loading...
;
if (error) return Error :(
;
return data.todos.map(({ id, type }) => {
let input;
return (
{type}
);
});
}