@bellawatt/react-hooks

1.3.1 • Public • Published

react-hooks

A collection of hooks we find ourselves turning to in multiple projects

NPM JavaScript Style Guide

Install

npm install --save @bellawatt/react-hooks

Usage

useDebounceEffect

import React, { useState } from 'react'
import axios from 'axios';
import { useDebounceEffect } from '@bellawatt/react-hooks'

const DebounceEffectExample = () => {
  const [value, setValue] = useState('');

  useDebounceEffect(() => {
    someSlowFunction();
  }, 1000, [value]));

  return (
    <div>
      <input value={value} onChange={e => setValue(e.currentTarget.value)} />
    </div>
  )
}

useToggle

import React from 'react'
import { useToggle } from '@bellawatt/react-hooks'
import { Modal } from 'reactstrap'

const ToggleExample = () => {
  const [open, toggle] = useToggle(false)

  return (
    <Modal isOpen={open} toggle={toggle}>
      ...
    </Modal>
  )
}

useLocalStorage

import React from 'react'
import { useLocalStorage } from '@bellawatt/react-hooks'

const LocalStorageExample = () => {
  const [storedData, setStoredData] = useLocalStorage('name-of-key')

  // ..
}

useGoogleAnalytics

** Requires a peer of react-router-dom and react-ga **

import React from 'react'
import { useGoogleAnalytics } from '@bellawatt/react-hooks'

const GoogleAnalyticsExample = () => {
  useGoogleAnalytics('google-key')

  // ..
}

useQueryString

** Requires a peer of react-router-dom **

import React from 'react'
import { useQueryString } from '@bellawatt/react-hooks'

const QueryStringExample = () => {
  const [urlInputs, updateQueryString] = useQueryString()

  // ..
}

License

MIT © bellawatt


This hook is created using create-react-hook.

Dependencies (0)

    Dev Dependencies (41)

    Package Sidebar

    Install

    npm i @bellawatt/react-hooks

    Weekly Downloads

    15

    Version

    1.3.1

    License

    MIT

    Unpacked Size

    1.46 MB

    Total Files

    28

    Last publish

    Collaborators

    • bknoles
    • brandonshar