@franciscomcg/use-norris
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

useNorris

Chuck Norris

useNorris is a React custom Hook that fetches random jokes about our hero Chuck Norris.

It has been built with TypeScript, TSDX and is the support for a training provided by the author.

NPM

The package is hosted in the NPM registry and can be found here.

Install

npm i @franciscomcg/use-norris

or

yarn add @franciscomcg/use-norris

Usage

import * as React from 'react';

import useNorris from '@franciscomcg/use-norris';

const App = () => {
  const initialState = {
    response: '',
    isLoading: false,
    isError: false,
    errorMessage: null,
  };
  const { response, isLoading, isError, errorMessage } = useNorris(
    initialState
  );

  if (errorMessage) {
    return <p>{errorMessage}</p>;
  }

  if (isError) {
    return <p>Something went wrong</p>;
  }

  if (isLoading) {
    return <p>Loading...</p>;
  }

  if (response) {
    return <p>{response.value}</p>;
  }
  return <p>Something went wrong</p>;
};

export default App;

License

MIT © FranciscoMCG

Readme

Keywords

none

Package Sidebar

Install

npm i @franciscomcg/use-norris

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

121 kB

Total Files

22

Last publish

Collaborators

  • franciscomcg