Skip to content

Improving useFetch error

Latest
Compare
Choose a tag to compare
@ilyalesik ilyalesik released this 12 Feb 09:32
· 78 commits to master since this release

Has implemented the ability to get error status code:

...

const Component = () => {
  const { isLoading, data, error } = useFetch("https://swapi.co/api/people/1");

  if (error) {
    return <div>
      <p>Code: ${error.status}</p>
      <p>Message: ${error.statusText}</p>
    </div>
  }
 
  ...
};