@franciscomcg/use-norris
v1.1.1
Published
![Chuck Norris](./src/images/chuck-norris.png)
Downloads
1
Readme
useNorris
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