Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useQuery by click

// emulates a fetch (useQuery expects a Promise)
const emulateFetch = _ => {
  return new Promise(resolve => {
    resolve([{ data: "ok" }]);
  });
};

const handleClick = () => {
  // manually refetch
  refetch();
};

const { data, refetch } = useQuery("my_key", emulateFetch, {
  refetchOnWindowFocus: false,
  enabled: false // disable this query from automatically running
});

return (
  <div>
    <button onClick={handleClick}>Click me</button>
    {JSON.stringify(data)}
  </div>
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: example of call by value and call by reference in javascript 
Javascript :: jquery has class 
Javascript :: update karma jasmine to specific version 
Javascript :: loading page for all ajax call in jquery 3.3.1 
Javascript :: angularjs date 
Javascript :: lazy load npm package 
Javascript :: axios put request 
Javascript :: submit form jquery browser check 
Javascript :: alphabetize text in javascript 
Javascript :: localstorage getitem 
Javascript :: redis to promise 
Javascript :: puppeteer click element with custom property 
Javascript :: can be converted to number js 
Javascript :: how to apply reduce to an empty array in javascript 
Javascript :: switch new date getday javascript 
Javascript :: node js code for saving first middle and last name 
Javascript :: react useeffect hooks 
Javascript :: Limit number of selected chekboxes 
Javascript :: react multiple classname 
Javascript :: alpine js x-on click not working 
Javascript :: cookie-session use in node 
Javascript :: send sms with twilio 
Javascript :: sequelize db:create test environment 
Javascript :: spotify uri 
Javascript :: javascript split method 
Javascript :: array last element 
Javascript :: parseint() javascript 
Javascript :: angular formatting numbers with -commas 
Javascript :: js class syntax 
Javascript :: create component in react 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =