Skip to content

nexys-system/react-headless

Repository files navigation

Headless components for React

npm version Publish Deployment

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)
    }
  }
}

Associated Resources

Old versions