reactive localstorage in react
function useStorageWatcher(key) {
const [val, setVal] = useState(localStorage.get(key));
useEffect(() => {
const handler = () => val !== localStorage.get(key) && setVal(localStorage.get(key));
window.addEventListener("storage", handle);
() => window.removeEventListener("storage", handler);
}, []);
useEffect(() => {
setVal(localStorage.get(key));
}, [key]);
return val;
}
Also in JavaScript:
- javascript turn string into array
- comment out in javascript
- what is public key
- javascript count digits
- javascript convert string to json object
- restful react npm
- switch two values each case js
- change js to json
- chamar arquivo javascript no html
- javascript keywords
- geolocation speed
- How can I get or extract some string part from url jquery
- react native backgrunde img
- javascript month name
- jquery droppable allow what can be dropped
- vue js error mixed spaces and tabs no-mixed-spaces-and-tabs
- javascript date now
- how to select div js
- create window electron
- change title react
- array.splice javascript
- agrgar atributo con id jquey
- preload images javascript
- datepicker using jquery