React custom hooks - uselocalstorage

Reading heart joy 2022-05-14 14:20:03 阅读数:139

reactcustomhooksuselocalstorage

Encapsulate any function , It is to encapsulate some repeated logic into a function . Not for packaging .

Definition useLocalStorage, Because localStorage, Get... In different components , to update . Every update or acquisition is localStorage.setItem/localStorage.getItem.

Individually packaged as a hook, When getting and updating , It's like using state It's as simple as :

useLocalStorage:

import {
 useState, } from 'react';
export default function useLocalStorage(key
版权声明:本文为[Reading heart joy]所创,转载请带上原文链接,感谢。 https://qdmana.com/2022/134/202205141415365850.html