@foreverrbum/ethsign
Version:
This package will allow you to electronically sign documents within your application
14 lines (10 loc) • 350 B
JavaScript
import {useState, useEffect} from "react";
export const useStateWithSessionStorage = (StorageKey, initialValue) => {
const [value, setValue] = useState(
JSON.parse(sessionStorage.getItem(StorageKey)) || initialValue
);
useEffect(() => {
sessionStorage.setItem(StorageKey, JSON.stringify(value));
}, [value]);
return [value, setValue];
};