Middle
Practical task: implement a call to the useMutation function so that 'Hello World' is printed to the console.
sobes.tech AI
Answer from AI
To call the useMutation function and log 'Hello World' to the console, you can do the following (example in React using Apollo Client):
import React from 'react';
import { useMutation, gql } from '@apollo/client';
const DUMMY_MUTATION = gql`
mutation Dummy {
dummy
}
`;
function HelloWorld() {
const [mutate] = useMutation(DUMMY_MUTATION, {
onCompleted: () => console.log('Hello World'),
});
React.useEffect(() => {
mutate();
}, [mutate]);
return <div>Check console for message</div>;
}
export default HelloWorld;
Here, useMutation returns the mutate function, which we call inside useEffect. After the mutation successfully completes, 'Hello World' is logged to the console. If the mutation is not needed, you can use any simple query or mock.