Created
May 5, 2023 08:34
-
-
Save JoviDeCroock/5583cdb15aa57913f87fc4d2d211687b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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