Skip to content

Latest commit

 

History

History
executable file
·
34 lines (21 loc) · 2.28 KB

README.md

File metadata and controls

executable file
·
34 lines (21 loc) · 2.28 KB

simple-hooks

This is a sample ReactJs application. It demonstrates one way to use React's built-in hooks such as useEffect and useState, as well as shows an an example of a custom hook in function-based components. Each successful request to the JSONPlaceholder API displays a list of sample data items corresponding to the tab clicked by the user.


users UsersList component

Material-UI React components are used for design and functional simplicity.

Custom Hook

A React custom hook useAxiosGetItems is demonstrated. The custom hook uses axios to request items from the JSONPlaceholder API. useAxiosGetItems is referenced by a service layer function called getResources. The custom hook returns list items, a loading boolean for a progress indicator, and any HTTP errors that occur during the request: return {listItems, loading, error}.

Setup

  1. Clone the repository: git clone https://github.com/bobmacneal/simple-hooks.git
  2. Install Yarn for package management.
  3. Install node dependencies using yarn: yarn

Run

  • Run app locally: yarn start

Hat Tips