Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

9.2.0

Compare
Choose a tag to compare
@jxom jxom released this 26 May 03:12
· 12 commits to master since this release

Features

  • Add ability to debounce invocation of the async function, using the debounce config option. Example:
async function fetchRandomDog({ value }) {
  const response = await axios.get(`https://dog.ceo/api/breed/${value}/images/random);
  return response;
}

export default function RandomDog() {
  const [value, setValue] = React.useState('poodle');

  const { isPending, isResolved, response } = useLoads('random-dog', fetchRandomDog, { 
    debounce: 1000,
    variables: [{ value }]
  });

  return (
    <div>
      <input 
        placeholder="Search for a dog..." 
        onChange={e => setValue(e.target.value)} 
        value={value} 
      />
      {isPending && 'Loading...'}
      {isResolved && (
        <img src={response.data.message} />
      )}
    </div>
  )
}