We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5bb34d0 + c1d4c1d commit c53a9a8Copy full SHA for c53a9a8
src/useStorage.js
@@ -5,7 +5,10 @@ import storage from "./storage";
5
function useStorage(...args) {
6
const initialValue = args.pop();
7
8
- const [state, setState] = useState(null);
+ const [state, setState] = useState(() => {
9
+ const item = storage.get(...args);
10
+ return item !== null ? item : initialValue;
11
+ });
12
13
useEffect(() => {
14
if (storage.get(...args) === null) {
0 commit comments