3.7.6 • Published 5 months ago

http-react v3.7.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

3.7.5

7 months ago

3.7.4

7 months ago

3.7.3

7 months ago

3.7.2

7 months ago

3.7.6

5 months ago

3.6.9

7 months ago

3.6.8

8 months ago

3.7.1

7 months ago

3.7.0

7 months ago

3.6.92

7 months ago

3.6.91

7 months ago

3.6.2

1 year ago

3.6.1

1 year ago

3.6.0

1 year ago

3.6.6

12 months ago

3.6.5

12 months ago

3.6.4

12 months ago

3.6.3

12 months ago

3.6.7

12 months ago

3.5.3

1 year ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.5.7

1 year ago

3.5.6

1 year ago

3.5.5

1 year ago

3.5.4

1 year ago

3.5.9

1 year ago

3.5.8

1 year ago

3.4.1

1 year ago

3.4.0

1 year ago

3.3.9

1 year ago

3.3.8

1 year ago

3.3.7

1 year ago

3.3.6

1 year ago

3.3.5

1 year ago

3.3.4

1 year ago

3.3.1

1 year ago

3.3.0

1 year ago

3.3.3

1 year ago

3.3.2

1 year ago

3.2.9

1 year ago

3.2.8

1 year ago

3.2.7

1 year ago

3.2.6

1 year ago

3.2.5

1 year ago

3.2.4

1 year ago

3.2.1

2 years ago

3.2.3

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.9.9

2 years ago

2.9.8

2 years ago

2.9.7

2 years ago

2.9.6

2 years ago

2.9.5

2 years ago

2.9.4

2 years ago

2.9.3

2 years ago

2.9.2

2 years ago

2.9.1

2 years ago

2.9.0

2 years ago

2.8.3

2 years ago

2.8.2

2 years ago

2.8.1

2 years ago

2.8.0

2 years ago

2.7.9

2 years ago

2.7.8

2 years ago

2.7.7

2 years ago

2.7.6

2 years ago

2.7.5

2 years ago

2.7.4

2 years ago

2.7.3

2 years ago

2.7.2

2 years ago

2.7.1

2 years ago

2.7.0

2 years ago

2.6.9

2 years ago

2.6.8

2 years ago

2.6.7

2 years ago

2.6.6

2 years ago

2.6.5

2 years ago

2.6.4

2 years ago

2.6.3

2 years ago

2.6.2

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.5.9

2 years ago

2.5.8

2 years ago

2.5.7

2 years ago

2.5.6

2 years ago

2.5.5

2 years ago

2.5.4

2 years ago

2.5.3

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.0

2 years ago

2.4.9

2 years ago

2.4.8

2 years ago

2.4.7

2 years ago

2.4.6

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.9

2 years ago