@david-sling/react-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

react-hooks

useful react hooks

NPM JavaScript Style Guide

Install

npm install --save react-hooks

Usage

import React from 'react'
import {
  useLocalStorage,
  useFetch,
  useAsyncEffect,
  useAsyncMemo,
  useEventListener
} from '@david-sling/react-hooks'

const Example = () => {
  const [text, setText] = useLocalStorage<string>('text', 'initial value')

  const [data, dataLoading<boolean>, dataError] = useFetch<any>(
    url, // url
    {}, // Initial value
    { body: { text }, method: 'GET' }, //params
    [url, text] // dependency array (Data will be refetched if any item in this array changes)
  )

  const [data, setData, reloadData] = useAsyncMemo(async () => "RETURN FROM ASYNC FUNCTION")

  useAsyncEffect(async() => {
    await asyncStuffHappensHere()
  }, [])

  useEventListener("click", () => console.log("Clicked"))

  const ref = useOutsideClick(() => {
    console.log("Clicked outside the div)
  })

  return <di ref={ref}v>APP</div>
}

License

MIT © david-sling

Readme

Keywords

none

Package Sidebar

Install

npm i @david-sling/react-hooks

Weekly Downloads

0

Version

1.3.3

License

MIT

Unpacked Size

41 kB

Total Files

14

Last publish

Collaborators

  • david-sling