Releases: atomic-state/http-react
Releases · atomic-state/http-react
v3.0.2
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
Fix: suspense
Fixed the Too many re-renders problem when using multiplie components with suspense
v3.0.0
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 asAxios
. Thefetcher
function must return an object with at least thedata
andstatus
properties (you can also return ajson
method instead ofdata
). - The object created with
Client.create
now also includes theconfig
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
Fix: cancel, SSRSuspense
- Requests always get cancelled after props change
- Fixed the
SSRSuspense
component. It can now wrap more than one instance of the sameuseFetch
v2.9.7
Fix: re-renders, onPropsChange
- Fixes unnecesart initial re-render
- Removed the
onPropsChange
api
v2.9.6
Feat: useFetch
, requestStart
, requestEnd
, expiration
- Makes
useFetch
the default export - Returns
null
in dates ifexpiration
,end
, orstart
Dates are Invalid Dates - The
serialize
function now accepts thereplacer
function and thespaces
args. - Makes
Client
an object with its different methods instead of a function that gets its methods prototyped after its creation
v2.9.5
Fix: auto
in useDebounceFetch
auto
can be passed to the useDebounceFetch
hook
v2.9.4
- Fixed
loading
beingtrue
when revalidating if cache exp. > date - Added useDebounceFetch to replace passing
debounce
touseFetch
- Checks if
maxCacheAge
has changed between renders to invalidate existing cache
v2.9.3
Fix: cacheIfError
, hasData
:
- Returns
null
or data correctly whencacheIfError = false
. However, ifdefault
is present, that would be returned instead ofnull
. error
andhasData
are now boolean values instead oftrue | null
for better usage (for example,error.toString()
would not throw thecannot read property toString of null
error).