Code Monkey home page Code Monkey logo

Comments (7)

lisaWriteJava avatar lisaWriteJava commented on July 18, 2024 1

Thanks. I'm in the process of trying to filter out some stuff right now. It was much smaller when it started but the revisions things grew. Thanks again for your assistance. I think the confusion is this has so much code from the changes and no deletions.

from mui-x.

michelengelen avatar michelengelen commented on July 18, 2024

When receiving the state from localStorage is it in JSON format. You have to parse this to apply it with apiRef.current.restoreState(). Example:

if (apiRef.current && stateFromLocal) {
  apiRef.current.restoreState(JSON.parse(stateFromLocal));
}

After that change it will work!

from mui-x.

lisaWriteJava avatar lisaWriteJava commented on July 18, 2024

Thanks this is working. 1 other question, how do I get the list of saved stated to update in the dropdown once I delete 1.

from mui-x.

michelengelen avatar michelengelen commented on July 18, 2024

You have implemented a reducer for that... at least it does look like it.
Think of the reducer as your internal state. Now on unmounting the component (or navigating away) you should store the current reducer state to localStorage and retrieve it once you mount the component or navigate back to it.

But the details of this implementation are up to you and a good place to ask these kinds of questions would be StackOverflow. The community there can help you with that problem.

If the original issue is resolved please feel free to close the issue. Thanks! 🙇🏼

from mui-x.

lisaWriteJava avatar lisaWriteJava commented on July 18, 2024

Thanks, I thought that the support purchased was to assist with questions such as these. Sorry to trouble you.

from mui-x.

github-actions avatar github-actions commented on July 18, 2024

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @lisaWriteJava?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

from mui-x.

michelengelen avatar michelengelen commented on July 18, 2024

Thanks, I thought that the support purchased was to assist with questions such as these. Sorry to trouble you.

Typically you would be right, but the question you asked is unrelated to our components and more of a general react question. We do provide a demo on how to store and restore state from localStorage. With a slight variation on this you should be able to implement the desired behavior. Just use the methods described there and change the "point of contact" as well as the data flow to when you initialize/mount (and later unmount) your reducer.

Basically the place where you pass in DEMO_INITIAL_STATE you need to pass in the state you retrieved from localStorage.

Now for deletion you just need to update the List you pass the state from the reducer instead of the one from localStorage

{Object.keys(state).map((label, index) => (
  <ViewListItem
    label={label}
    index={index}
    onDelete={handleDeleteView}
    onSelect={() => handleSetActiveView(label, index)}
  />
))}

This should be enough to fix the problem. You should think about separating the code as well. it is hard to navigate like this. Just as a tip! 👍🏼

from mui-x.

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.