sdr34 / react-hook-kit

React Hook Kit: A TypeScript library of reusable custom hooks for accelerating React application development.
MIT License
4 stars 3 forks source link

Implementation of useLocalStorage hook #4

Closed sdr34 closed 1 year ago

sdr34 commented 1 year ago

Task Description I would like to add the useLocalStorage hook to the library, which will simplify working with browser's localStorage. This hook will allow convenient reading and writing of data to localStorage, as well as automatically updating components when the data in localStorage changes.

Expected Behavior The useLocalStorage hook should accept a key and an initial value as arguments. Upon component mount, the hook should read the value from localStorage using the specified key. If the value is not found, the initial value should be used. When the value of useLocalStorage changes, it should be written to localStorage using the specified key. Components using the useLocalStorage hook should automatically update when the data in localStorage changes. Additional Requirements The useLocalStorage hook should be written in TypeScript and should be well-tested. Documentation and usage examples should be added to the README.md. Related Tasks None

Proposed Solution The built-in localStorage object can be used for reading and writing data. The useState hook can be used to track and update the value in the storage and components. I would be happy to contribute to the implementation of this task and provide any necessary assistance.