@nexys/headless
v1.2.19
Published
[![npm version](https://img.shields.io/npm/v/@nexys/headless)](https://www.npmjs.com/package/@nexys/headless) [![Publish](https://github.com/nexys-system/react-headless/actions/workflows/publish.yml/badge.svg)](https://github.com/nexys-system/react-headle
Downloads
546
Maintainers
Readme
Headless components for React
React headless components - Quickly build robust react apps
- no UI dependencies
- Minimal bootstrap implementation
- Typescript, all props typed
Get started
yarn add @nexys/headless
UI Components
All components fitting ui-type.ts
must be created for a particular design system.
Then instantiate list-super
with the created UI components
see example here
Requests
Create a request function that extends https://github.com/nexys-system/react-headless/blob/master/src/lib/request/fetch.ts#L4
below an untested implementation example:
const request = <A, B = any>(
url: string,
method:Method = "GET",
data?: B
): Promise<A> => {
try {
return fetchJSON(url, {method, data});
} catch (err) {
if(err.message) {
throw Error(err)
}
const {status, data}:{status:number, data?:any} = err;
if (status === 401) {
// user unauthenticated, redirect to login?
}
if (status === 403) {
// not enough permissions, display toast
}
if (status === 500) {
// todo
}
if (status === 400) {
return Promise.reject(data)
}
}
}