How to use the rest-hooks.useError function in rest-hooks

To help you get started, we’ve selected a few rest-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coinbase / rest-hooks / packages / legacy / src / index.ts View on Github external
export function useStatefulResource<
  Params extends Readonly,
  S extends Schema
>(fetchShape: ReadShape, params: Params | null) {
  const maybePromise = useRetrieve(fetchShape, params);
  const state = useContext(__INTERNAL__.StateContext);
  const [denormalized, ready] = useDenormalized(fetchShape, params, state);

  const loading = Boolean(
    !__INTERNAL__.hasUsableData(ready, fetchShape) &&
      maybePromise &&
      typeof maybePromise.then === 'function',
  );

  const error = useError(fetchShape, params, ready);

  return {
    data: denormalized,
    loading,
    error,
  };
}