View Code? Open in Web Editor
NEW
React hook to easily manage the Local Storage
Home Page: https://github.com/franlol/useLocalStorage
HTML 18.89%
JavaScript 56.24%
CSS 2.80%
TypeScript 22.06%
uselocalstorage's Introduction
- ๐ HTML | CSS | Typescript | Node
- ๐ฎ React | Redux | NextJS | Express | GraphQL
- โ
Jest | React-testing-library
- ๐๏ธ ๏ธSQL | MongoDB
- ๐จ Git | Jenkins
- ๐ฅ๏ธ ๏ธLinux
- ๐ Robotics Superior Technician & Web Developer Superior Technician
- ๐ Working as a Full Stack MERN Developer
- ๐ฑ Improving in cyber security
- ๐ I love to be updated, as I believe it is the key to being successful
- ๐ But not everything is is about computers... I also love the ocean
- ๐คฟ I'm a PADI certified Scuba Diver:
uselocalstorage's People
Contributors
Watchers
uselocalstorage's Issues
For example useLocalStorage('key', 'defaultvalue')
useState
is conditionally called which is against the rules of hooks: https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level
export const useLocalStorage = (key: string) => {
if (typeof window === 'undefined' || typeof key !== 'string' || !key) {
return [null, (_: string) => null];
}
const [value, setValue] = useState<string>(window.localStorage.getItem(key) || '');