Skip to content

Commit c53a9a8

Browse files
authored
Merge pull request #4 from NucleoidJS/usestorage-initialstate-change
Change initial state
2 parents 5bb34d0 + c1d4c1d commit c53a9a8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/useStorage.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import storage from "./storage";
55
function useStorage(...args) {
66
const initialValue = args.pop();
77

8-
const [state, setState] = useState(null);
8+
const [state, setState] = useState(() => {
9+
const item = storage.get(...args);
10+
return item !== null ? item : initialValue;
11+
});
912

1013
useEffect(() => {
1114
if (storage.get(...args) === null) {

0 commit comments

Comments
 (0)