Updating Local Storage

Hi there

I am trying to update local storage, but for the life of me I cannot get the syntax of the key correct in the localStorage.setValues function. The data in localStorage looks like this, and I am trying to update the build_id. Can anyone give me some pointers please...?

image

Thanks

Adam

You may want to try using setIn not setValues

localStorage.setIn([0, "build_id"], value_you_want_to_put_in_build_id);

0 is the index within your localStorage in your screenshot.

Here's a similar use case but uses tempStates instead...

Hey @turps808 the suggestion that @ScottR gave is ideal but, unfortunately, there is no setIn function on localStorage :pensive:

The best recommendation I have is to create and update a copy of that value and then pass it back, for instance, in a JS query you can write:

const data = localStorage.values.data;
data[0].build_id = 21003;
localStorage.setValue("data", data);

Let me know if something like that works or if it raises other questions.

I did not know that localStorage doesn’t support setIn. So thanks for that. Seems that temp states might be a better way to go. That’s just my opinion.

Hi Kabirdas

Many thanks for the thoughts - i will give your suggestion a go.

In terms of the technical difference between local storage and temp state, are you able to give me a quick run down off the differences?

For performance reasons I am looking to copy all of my data (from Firestore) and then work with it locally before saving changes back to the DB. In this scenario would you recommended one option over the other?

Many thanks

Adam

1 Like

Many thanks for the thoughts Scott :grinning:

Yea! In my opinion, the biggest reason to use localStorage is if you want some kind of persistence for a particular user between sessions. Otherwise, temp state integrates a little better with your Retool app, being able to use setIn is a great example of that, you can also use the UI of certain event handlers to set temp state values, etc.

I agree with @ScottR that temp state seems like a good way to go here :slightly_smiling_face: do you have any particular wants with respect to how you're storing your data for manipulation?