Simplify "useStorage" hook
This commit is contained in:
@@ -34,8 +34,7 @@ function useStorage<T>(
|
|||||||
// Allow value to be a function so we have same API as useState
|
// Allow value to be a function so we have same API as useState
|
||||||
const valueToStore = (() => {
|
const valueToStore = (() => {
|
||||||
if (value instanceof Function) {
|
if (value instanceof Function) {
|
||||||
const previousValue =
|
const previousValue = storage.getItemParsed(key, initialState);
|
||||||
jsonSaveParse(storage.getItem(key) ?? '') ?? storage.getItemParsed(key, initialState);
|
|
||||||
|
|
||||||
return value(previousValue);
|
return value(previousValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user