0.1.3 • Published 3 years ago

@goldenjayr/use-fetch v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Use Fetch by @goldenjayr

This hook uses axios under the hood. This hook makes good use of React Suspense

    import useFetch from '@goldenjayr/use-fetch'
    import { Suspense } from 'react'

    function Todos() {
      const options = {} // these options accept all native `axios` options
      // the last argument below [] means it will fire onMount (GET by default)
      const data = useFetch({ url: 'https://example.com/todos', options })
      return (
        <>
          {data}
        </>
      )
    }


    function App() {
      return (
        // you need to wrap your component in suspense
        <Suspense>
          <Todo />
        </Suspense>
      )
    }