@dhruv-m-patel/react-hooks
A library of custom react hooks for frontend projects
Using this package
-
Install this package
npm i -S @dhruv-m-patel/react-hooks # OR yarn add @dhruv-m-patel/react-hooks
-
Import custom hook from this package and use it in your component
import * as React from 'react'; import { useFetch } from '@dhruv-m-patel/react-hooks'; import { Text } from '@dhruv-m-patel/react-components'; export default function MyAwesomeComponent({ apiEndpoint }) { const { loading, error, data } = useFetch(apiEndpoint); if (loading) { return ( <Text>Loading data....</Text> ); } if (error) { return ( <Text>Oops, There was an error fetching data!</Text> ); } return ( <Text>{JSON.stringify(data)}</Text> ); }