use-local-storage-state
Advanced tools
Comparing version 6.0.2 to 6.0.3
declare type UpdateState<T> = { | ||
reset: () => void; | ||
(newValue: T | ((value: T) => T)): void; | ||
reset: () => void; | ||
}; | ||
@@ -5,0 +5,0 @@ export default function useLocalStorageState<T = undefined>(key: string): [T | undefined, UpdateState<T | undefined>, boolean]; |
@@ -97,3 +97,3 @@ "use strict"; | ||
value: newValue(state.value), | ||
isPersistent: storage.set(key, newValue), | ||
isPersistent: storage.set(key, newValue(state.value)), | ||
})); | ||
@@ -110,6 +110,6 @@ } | ||
storage.remove(key); | ||
setState({ | ||
setState((state) => ({ | ||
value: defaultValueState, | ||
isPersistent: state.isPersistent, | ||
}); | ||
})); | ||
}; | ||
@@ -132,3 +132,3 @@ return fn; | ||
return () => void initializedStorageKeys.delete(key); | ||
}, []); | ||
}, [key]); | ||
/** | ||
@@ -148,3 +148,3 @@ * Syncs changes across tabs and iframe's. | ||
return () => window.removeEventListener('storage', onStorage); | ||
}, [defaultValueState]); | ||
}, [key, defaultValueState]); | ||
/** | ||
@@ -151,0 +151,0 @@ * Update the state when the `key` property changes. |
{ | ||
"name": "use-local-storage-state", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "React hook that persist data in local storage. Done right.", | ||
@@ -30,3 +30,4 @@ "license": "MIT", | ||
"build": "tsc", | ||
"test": "yarn run build && [[ -z $CI ]] && jest --coverage --coverageReporters=text || jest --coverage", | ||
"lint": "eslint --cache --format=pretty --ext=.ts ./", | ||
"test": "yarn run build && yarn run lint && [[ -z $CI ]] && jest --coverage --coverageReporters=text || jest --coverage", | ||
"release": "yarn run build && np", | ||
@@ -50,2 +51,12 @@ "prettier": "prettier --write --config .prettierrc.yaml {*.ts,*.json}" | ||
"@types/react-dom": "^16.9.8", | ||
"@typescript-eslint/eslint-plugin": "^4.11.0", | ||
"@typescript-eslint/parser": "^4.11.0", | ||
"confusing-browser-globals": "^1.0.10", | ||
"eslint": "^7.16.0", | ||
"eslint-config-strictest": "^0.3.1", | ||
"eslint-formatter-pretty": "^4.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-react": "^7.21.5", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"eslint-plugin-unicorn": "^24.0.0", | ||
"jest": "^25.1.0", | ||
@@ -52,0 +63,0 @@ "np": "7.0.0", |
@@ -25,3 +25,3 @@ # `use-local-storage-state` | ||
- Subscribes to the Window [`storage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event) event which tracks changes across browser tabs and iframe's | ||
- [My open-source principles](https://github.com/astoilkov/me/blob/master/essays/My%20open-source%20principles.md) aim for quality and maintenance | ||
- High quality with [my open-source principles](https://github.com/astoilkov/me/blob/master/essays/My%20open-source%20principles.md) | ||
@@ -28,0 +28,0 @@ ## Usage |
16306
22