Skip to content

Instantly share code, notes, and snippets.

@JoviDeCroock
Created May 5, 2023 08:34
Show Gist options
  • Save JoviDeCroock/5583cdb15aa57913f87fc4d2d211687b to your computer and use it in GitHub Desktop.
Save JoviDeCroock/5583cdb15aa57913f87fc4d2d211687b to your computer and use it in GitHub Desktop.
import React from 'react';
import { useClient, gql } from 'urql';
const TodoQuery = gql`
query($id: ID!) {
todo(id: $id) {
id
text
}
}
`;
function NameLoader(props) {
const [showTodo, setShowTodo] = useState(false)
const client = useClient();
return (<>
<Button
onClick={() => {
client.query(TodoQuery, {id: '4'})
setShowTodo(true)
}}
>
Visit todo
</Button>
<Suspense fallback="Loading...">
{showTodo
? <Todo id="4" />
: null
}
</Suspense>
</>);
}
function Todo({ id }) {
const result = useQuery({ query: TodoQuery, variables: { id } })
return <p>{result.data.todo?.text}</p>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment