Untitled

 avatar
unknown
tsx
2 years ago
455 B
2
Indexable
  useEffect(() => {
    setTimeout(() => {
      const item = localStorage.getItem(key);
      if (item) {
        try {
          const decryptState = CryptoJS.AES.decrypt(item, protectKey).toString(
            CryptoJS.enc.Utf8,
          );
          setState(JSON.parse(decryptState));
        } catch {
          localStorage.removeItem(key);
        }
      } else {
        setState(initialValue);
      }
    }, 10);
  }, [asPath, initialValue]);