Code Monkey home page Code Monkey logo

Comments (5)

astoilkov avatar astoilkov commented on May 20, 2024 1

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.

rwieruch avatar rwieruch commented on May 20, 2024

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.

astoilkov avatar astoilkov commented on May 20, 2024

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.

astoilkov avatar astoilkov commented on May 20, 2024

Hey @rwieruch. Just a reminder. Did you have time to see what I'm proposing?

from use-local-storage-state.

astoilkov avatar astoilkov commented on May 20, 2024

I'm closing this because of a lack of activity.

from use-local-storage-state.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.