http-react
TypeScript icon, indicating that this package has built-in type declarations

3.7.5 • Public • Published

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'

// This is the default fetcher.
const fetcher = (url, config) => fetch(url, config)

export default function App() {
  const { data, loading, error, responseTime } = useFetch('/api/user-info', {
    refresh: '30 sec',
    fetcher
  })

  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 also works with Next.js' server functions:

// actions.ts
'use server'

import { actionData } from 'http-react'

export async function getData({ id }: { id: number }) {
  return actionData({
    foo: 'bar'
  })
}
// page.tsx
'use client'
import { useAction } from 'http-react'

import { getData } from '@/actions'

export default function Page() {
  // data has static typing inferred from the action result
  const { data, isPending, error } = useAction(getData, {
    params: {
      id: 1 // This will show an error if id is not a number
    }
  })

  return isPending ? (
    <p>Loading...</p>
  ) : error ? (
    <p>Something went wrong</p>
  ) : (
    <div>
      <h2>Welcome</h2>
      <p>{data.foo}</p>
    </div>
  )
}

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

  • Server-Side Rendering
  • Server actions
  • React Native
  • Request deduplication
  • Suspense
  • Refresh
  • Retry on error
  • Pagination
  • Local mutation (Optimistic UI)
  • qraphql

and more!

Installation:

npm install --save http-react

Or

yarn add http-react

Getting started

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.7.514latest

Version History

VersionDownloads (Last 7 Days)Published
3.7.514
3.7.41
3.7.31
3.7.25
3.7.10
3.7.00
3.6.921
3.6.912
3.6.90
3.6.80
3.6.713
3.6.60
3.6.50
3.6.41
3.6.31
3.6.20
3.6.11
3.6.00
3.5.90
3.5.81
3.5.70
3.5.61
3.5.52
3.5.40
3.5.30
3.5.20
3.5.11
3.5.00
3.4.10
3.4.02
3.3.90
3.3.81
3.3.70
3.3.60
3.3.50
3.3.40
3.3.30
3.3.20
3.3.11
3.3.01
3.2.90
3.2.80
3.2.70
3.2.60
3.2.50
3.2.40
3.2.30
3.2.10
3.2.01
3.1.01
3.0.60
3.0.50
3.0.40
3.0.30
3.0.20
3.0.10
3.0.00
2.9.90
2.9.80
2.9.70
2.9.60
2.9.50
2.9.40
2.9.30
2.9.20
2.9.10
2.9.00
2.8.30
2.8.20
2.8.10
2.8.00
2.7.90
2.7.80
2.7.70
2.7.60
2.7.50
2.7.40
2.7.30
2.7.20
2.7.10
2.7.00
2.6.90
2.6.80
2.6.70
2.6.60
2.6.50
2.6.40
2.6.30
2.6.20
2.6.10
2.6.00
2.5.90
2.5.80
2.5.70
2.5.60
2.5.50
2.5.40
2.5.30
2.5.20
2.5.10
2.5.00
2.4.90
2.4.80
2.4.70
2.4.60
2.4.50
2.4.40
2.4.30
2.4.20
2.4.10
2.4.00
2.3.90

Package Sidebar

Install

npm i http-react

Weekly Downloads

52

Version

3.7.5

License

MIT

Unpacked Size

236 kB

Total Files

33

Last publish

Collaborators

  • danybeltran