Releases: atomic-state/http-react
Releases · atomic-state/http-react
v2.8.2
fix: error, data, loading:
sets the 'loading', 'data' and 'error' state in the right order
v2.7.8
Feat: server components
re-exports FetchConfig and SSRSuspense from separate module with use client directive. Now FetchConfig can be imported directly from http-react instead of http-react/dist/server when using Server components
v2.7.5
Feat: FetchConfig
Adds re-export of FetchConfig that can be used inside Next.js's server components:
import { FetchConfig } from 'http-react/dist/server'
export default async function Layout({ children }) {
return (
<div>
<FetchConfig baseUrl='/api'>{children}</FetchConfig>
</div>
)
}v2.7.0
Fix: onError, graphql
- verifies if 'onError' is a function. Sets 'error' state correctly
- Notifies other subscribers when a graphql request has finished
v2.6.8
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>v2.6.7
Feat: HttpReact client (works with sever components)
- Adds the
HttpReactobject, which can be used to make requests imperatively. It has a method for each HTTP verb, likeget,post, etc. It also has anextendmethod, similar toaxios.create
Example with a sever component in Next.js:
import { HttpReact } from 'http-react'
import { cookies } from 'next/headers'
export default async function MyServerPage() {
const session = cookies().get('appSession')?.value
const { data, error } = await HttpReact.get('/api/auth', {
headers: { Authorization: 'Token ' + session }
})
if (!data || error) return <Login />
return <App />
}Using .extend:
import { HttpReact } from 'http-react'
const client = HttpReact.extend({
baseUrl: '/api',
headers: {
Authorization: 'Token'
}
})
export default async function MyServerPage() {
const { data, error } = await client.get('/auth')
if (!data || error) return <Login />
return <App />
}This also works in client-side components and with getServerSideProps
v2.6.5
Feat: initialization
The first request is sent before the first render
v2.6.4
Fix: loading
- Makes the
loadingstate more reliable - exposes
defaultCachefromsrc/internal
v2.6.3
Feat: use client
adds use client to main library file, which makes it possible to use FetchConfig inside Server components in Next.js
v2.6.2
Feat: dates and auto
- Fixed request being sent even with
autoset tofalse useFetchnow also returnsrequestStartandrequestEnd, which are the Date objects in which the request started and ended, specificalyrefresh,attemptIntervalanddebouncenow need to be aTimeSpan. If you pass a number, it will be taken as miliseconds. You can also pass a string (e.g.,10 sec,30 min,1 w, etc). If a unit of time is not valid (e.g.30 secc), the amount will be taken as miliseconds