Add Efficient 'update' Method for Local Storage JSON Data

Hello Team!

It would be very useful to have an option to use an update method for local storage. I have a similar situation in several apps where I store large JSON files in local storage and need to update only one value somewhere inside. Currently, I copy the object from local storage, update the value, and save it back (using the setValue method) to local storage. Unfortunately, this approach has some drawbacks, especially when a user quickly triggers actions that initiate such updates in multiple places. An update method with a signature like update(key:, newValue:, path:) would likely solve these issues.

Please let me know what you think about it!

BR

6 Likes

Would setIn() not work? See here for example.

2 Likes

Hi @jg80

setIn is a method for variables, not local storage. This is exactly the method I would love to have for local storage.

3 Likes

Ah. Got it. I tend to create variables instead of using local storage, so my mind went there instead of thinking about the differences. Makes sense to me to add a setIn() function for local storage.

2 Likes

Hello @heynoway!

I can definitely make a request to see if our engineering team can add the function that would do the same thing as setIn but for local storage.

Because local storage is a part of the browser, this may be outside the scope of Retool's capabilities but it doesn't hurt to ask.

As @jg80 eloquently points out, Retool variables can be used in the exact same way to save data in a from end 'state' and already has the setIn method for being able to quickly and efficiently find a value by a key and replace its value with the new data passed in as a function arg.

1 Like

Thanks @Jack_T !

I use local storage to preserve certain values when navigating between different applications, as variables cannot accomplish this.

1 Like

Ah interesting, have you tried using multipage apps? That might be easier to pass data between the pages instead of having to move data across separate apps :thinking:

Hi @Jack_T,

It's not just for apps; it's also useful when working with modules that update data. You don’t need to pass out any parameters or merge data in any way. I have solutions based on local storage that were created before multipage apps were introduced, and everything works as expected.

1 Like

Ah ok thank you for sharing!

Will keep you updated on any news for the feature request to add in a method for quick insert to local storage.

I would imagine that this could be done as a custom JS Query block but might be complex and if we can have a built in tool that is reusable for all users that would definitely help with such use cases.