JSPM

  • Created
  • Published
  • Downloads 380
  • Score
    100M100P100Q70153F
  • License MIT

React hooks for data fetching

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (http-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    HTTP React

    Http React is a React hooks library for data fetching. It's built on top of the native Fetch API.

    Overview

    With one hook call, you get all the information about a request that you can use to build UIs that are consistent and performant:

    import useFetch from "http-react"
    
    export default function App() {
      const { data, loading, error, responseTime } = useFetch("/api/user-info", {
        refresh: '30 sec'
      })
    
      if (loading) return <p>Loading</p>
    
      if (error) return <p>An error ocurred</p>
    
      return (
        <div>
          <h2>Welcome, {data.name}</h2>
          <small>Profile loaded in {responseTime} miliseconds</small>
        </div>
      )
    }

    It supports many features that are necessary in modern applications, while giving developers full control over the request configuration:

    • Server-Side Rendering
    • React Native
    • Request deduplication
    • Suspense
    • Refresh
    • Retry on error
    • Pagination
    • Local mutation
    • qraphql

    and more!

    Installation:

    npm install --save http-react

    Or

    yarn add http-react

    For production apps

    <!-- Add React and ReactDOM -->
    <script
      src="https://unpkg.com/react@18.2.0/umd/react.production.min.js"
      crossorigin
    ></script>
    
    <script
      src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js"
      crossorigin
    ></script>
    
    <!-- Add Http React -->
    <script src="https://unpkg.com/http-react/dist/browser/http-react.min.js"></script>

    Getting started