Table of Contents
Installation
npm install @invorious/http-client-front
Usage
import { useState } from 'react';
import { useHttpClient } from '@invorious/http-client-front';
export interface MyUser {
name: string;
id: number;
}
export function MyComponent() {
const [profile, setProfile] = useState<MyUser | undefined>();
const { get, post, put, deleteRequest, requestError } = useHttpClient({
config: {
baseUrl: 'api/',
headers: {
Authorization: 'Your authorization',
},
},
});
async function onGetProfile() {
const users = await get<MyUser>('me');
setProfile(users);
}
return (
<div>
{requestError ? (
<div>
Verify your request configuration.
<p>{requestError.message}</p>
</div>
) : (
<div>{JSON.stringify(profileuser)}</div>
)}
</div>
);
}
For more examples, please refer to the Documentation
Changelog
Learn about the latest improvements.