Comments (5)
I understand your scenario. Give me some time to think about this. I've seen people wanting to get the state only initially and then don't update it but I should think if there is a unifying solution that can fit all scenarios.
from use-local-storage-state.
My workaround at the moment:
const [resizedLayout] = useLocalStorage('table-widths', {
defaultValue: [],
});
// we do not want a re-render
// but only remember the table's columns widths
// to apply when the table gets rendered from scratch
// https://github.com/astoilkov/use-local-storage-state/issues/46
const setResizedLayout = (widths) => {
if (localStorage) {
localStorage.setItem('table-widths', JSON.stringify(widths));
}
};
from use-local-storage-state.
Is this solution going to work for you:
const [resizedLayout, setResizedLayout] = useLocalStorage('table-widths', {
defaultValue: [],
});
// in the code you always use `initialResizedLayout` and you can now call `setResizedLayout()` without causing your behavior to break
const initialResizedLayout = useRef(resizedLayout).current
As my users have written about the same problem I'm thinking of updating the readme. If this solution works for you I would think about explaining this scenario. The solution seems simple and elegant.
from use-local-storage-state.
Hey @rwieruch. Just a reminder. Did you have time to see what I'm proposing?
from use-local-storage-state.
I'm closing this because of a lack of activity.
from use-local-storage-state.
Related Issues (20)
- Additional type exports HOT 4
- Async storage lookup/default value issue HOT 20
- Setter in useEffect dependencies array always changes HOT 5
- Does not respond to changes to localStorage made elsewhere in the application HOT 2
- React 18 support (created by library author) HOT 8
- I have a problem using the use-local-storage-state HOT 7
- Hydration error with ssr:true using NextJS HOT 7
- need guidance for using sessionStorage also HOT 3
- Return isPossiblyHydrating HOT 4
- Usage Example contains "ssr: true", which does not appear to be a valid option HOT 1
- usage with reducer HOT 2
- Seems to be trying to fetch from local storage before window is defined in React/Next SSR environment HOT 6
- React 18: value only is available on 2nd render cycle HOT 13
- Latest version on npm is 17.3.0, rather than 18.2.0 HOT 3
- Could not find a declaration file for module 'use-local-storage-state'. HOT 4
- ✨ Make package ESM only
- block all cookies in safari breaks the hook HOT 9
- Next.js build error: targets must start with "./" HOT 2
- Migrating from `createLocalStorageStateHook` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-local-storage-state.