Query and Params
You can set global params and global URL search params. For example:
components/profile.jsx
export default function Profile() {
const { loading, data } = useFetch('/[userId]/profile')
if (loading) return <p>Loading profile</p>
return <div>Hello, {data.name}</div>
}
components/messages.jsx
export default function Messages() {
const { loading, data } = useFetch('/[userId]/messages')
if (loading) return <p>Loading messages</p>
return <div>{data.length} messages</div>
}
Inside App.tsx
:
src/App.tsx
import { FetchConfig } from 'http-react'
import Profile from 'components/profile'
import Messages from 'components/messages'
export default function App() {
return (
<FetchConfig
baseUrl='/api'
params={{
userId: 'some-user-id'
}}
query={{
date: '2023-01-23'
}}
>
<Profile />
<Messages />
</FetchConfig>
)
}
Last updated on January 31, 2023