Skip to content

Releases: atomic-state/http-react

v3.0.2

08 Feb 04:08
ed5ac01
Compare
Choose a tag to compare

Fix: performance

reFetch only re-renders when the accessed values change. This is done by keeping track of which values are read with React.useRef. For example, you may have a component that only reads the error returned by useFetch, in that case, the component will re-render only then the request fails. Same with loading and data

v3.0.1

04 Feb 19:03
9cc6e9e
Compare
Choose a tag to compare

Fix: suspense

Fixed the Too many re-renders problem when using multiplie components with suspense

v3.0.0

03 Feb 01:53
a61c35c
Compare
Choose a tag to compare

Feat: fetcher

  • The fetching mechanism is now configurable by passing the fetcher prop. This can be set globally using the <FetchConfig> context component or per-request. This opens the posibility of using other data-fetching libraries such as Axios. The fetcher function must return an object with at least the data and status properties (you can also return a json method instead of data).
  • The object created with Client.create now also includes the config property, which can be passed to the <FetchConfig> component.

Example of a custom fetcher with axios:

import useFetch from 'http-react'
import axios from 'axios'

const fetcher = (url, config) => axios(url, config)

export default function Profile() {
  const { data, loading, error, code, id } = useFetch('/api/profile', {
    fetcher
  })

  if (loading) return <p>Loading...</p>

  if (error) return <p>Failed to fetch</p>

  return (
    <div>
      <h2>Profile</h2>
      <p>Name: {data.name}</p>
    </div>
  )
}

v2.9.8

01 Feb 20:51
ceff5db
Compare
Choose a tag to compare

Fix: cancel, SSRSuspense

  • Requests always get cancelled after props change
  • Fixed the SSRSuspense component. It can now wrap more than one instance of the same useFetch

v2.9.7

01 Feb 16:30
6456c0b
Compare
Choose a tag to compare

Fix: re-renders, onPropsChange

  • Fixes unnecesart initial re-render
  • Removed the onPropsChange api

v2.9.6

30 Jan 15:42
f75b9ef
Compare
Choose a tag to compare

Feat: useFetch, requestStart, requestEnd, expiration

  • Makes useFetch the default export
  • Returns null in dates if expiration, end, or start Dates are Invalid Dates
  • The serialize function now accepts the replacer function and the spaces args.
  • Makes Client an object with its different methods instead of a function that gets its methods prototyped after its creation

v2.9.5

30 Jan 00:38
d86b0e0
Compare
Choose a tag to compare

Fix: auto in useDebounceFetch

auto can be passed to the useDebounceFetch hook

v2.9.4

30 Jan 00:12
1d41d1c
Compare
Choose a tag to compare
  • Fixed loading being true when revalidating if cache exp. > date
  • Added useDebounceFetch to replace passing debounce to useFetch
  • Checks if maxCacheAge has changed between renders to invalidate existing cache

v2.9.3

29 Jan 19:46
7f2b4cf
Compare
Choose a tag to compare

Fix: cacheIfError, hasData:

  • Returns null or data correctly when cacheIfError = false. However, if default is present, that would be returned instead of null.
  • error and hasData are now boolean values instead of true | null for better usage (for example, error.toString() would not throw the cannot read property toString of null error).

v2.9.2

29 Jan 05:25
44f4aa0
Compare
Choose a tag to compare

Fix: auto, suspense

  • If auto is false, loading should be false too unless revalidating. 65111fb
  • If auto is false, suspense will not initialize. f94701a