Skip to content

Instantly share code, notes, and snippets.

@bagus2x
Created August 5, 2021 06:59
Show Gist options
  • Save bagus2x/2b8832eb9fdd131101cc350b956925c9 to your computer and use it in GitHub Desktop.
Save bagus2x/2b8832eb9fdd131101cc350b956925c9 to your computer and use it in GitHub Desktop.
react query example when button is clicked
import React from 'react';
import { useQuery } from 'react-query';
function Playground() {
const { data, refetch } = useQuery(
'RANDOM',
async () => {
const res = await new Promise<number>((resolve) => setTimeout(() => resolve(Math.random()), 1000));
return res;
},
{
enabled: false
}
);
return (
<div>
<h1>{data}</h1>
<button onClick={() => refetch()}>Random</button>
</div>
);
}
export default Playground;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment