Untitled

mail@pastecode.io avatar
unknown
tsx
a year ago
455 B
1
Indexable
Never
  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]);