@24hr/react-hooks

1.2.2 • Public • Published

@24hr/react-hooks

All Contributors

Build

React hooks library

Documentation

useBeforeMount

A hook that runs before mount and is suitable for SSR.

useBeforeMount(() =>
    console.log('Runs only once before component mounts. Works on the server!')
)

useLocalStorage

A hook that syncs state with localstorage

/**
 * @typedef Options
 * @property {boolean} [clearOnUnmount] - Whether or not to clear the localstorage value on unmount.
 */

/**
 * A hook that syncs the state with a property in the localstorage.
 * @param {string} defaultVal - The initial value
 * @param {string} key - Mandatory key to use to store the data in localstorage.
 * @param {Options} options - Options object
 * @return {[any, function, function]} - Return the current state, a set state function and a function to clear the storage.
 */
const [state, setState, clear] = useLocalStorage('default value', 'key', { clearOnUnmount: false });

Want to contribute?

It's easy to contribute!

  1. Clone the repo and create a new branch from master.

  2. Make your changes.

  3. Run ./bump.sh and choose if your changes are major, minor och patch.

  4. Commit and push.

  5. Make a merge request to master. The CI pipeline will publish your new version to NPM!

Contributors

Thanks goes to these wonderful people (emoji key):


Marcus Thelin

💻

schmolie

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Readme

Keywords

none

Package Sidebar

Install

npm i @24hr/react-hooks

Weekly Downloads

10

Version

1.2.2

License

MIT

Unpacked Size

14.5 kB

Total Files

8

Last publish

Collaborators

  • inna.aleshina
  • simon.sporrong
  • mikaela.ruden
  • jaarni
  • daniumdev
  • thjo
  • richardsweeney
  • alexander-nilsson
  • camilo.tapia
  • 24hr-machine-user
  • insidenpm
  • bextex
  • victorglimskog
  • resurs-wikskold
  • younous_abdallah
  • resurs_software_solutions_machine_user