@invorious/http-client-front
v0.0.4
Published
[Comment: Environments by Logo]: # [Logo_Npm]: https://img.shields.io/badge/NPM-v0.0.0-blue [Logo_PRs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg [Logo_Chat]: https://img.shields.io/badge/Chat-Slack-7289da.svg [Logo_License]: https://img.sh
Downloads
9
Keywords
Readme
npm install @invorious/http-client-front
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
Learn about the latest improvements.