Reset temporary state in a module when inputs change

I have a module which takes in several inputs representing IDs in the database, and some temporary state internal to the module. When the inputs to the module change, I want to set the temporary state to its default values. How do I do this?

I found a workaround in order to do this, but it's not very clean:
First, I created another piece of temporary state to store all of the inputs in an object. Then I created a javascript query which would compare the inputs to the values in my new piece of temporary state. If there was a difference, the new query would reset the temporary state I was trying to reset and update the temporary state which stores the inputs. I then set the query to run on success for another query which used all of the inputs. It was cumbersome, but it worked. I would like to know if there's an easier way to do this in the future.

Hi @webster! I think your solution sounds good :blush:

You might also be able to do something similar with a dummy query that is triggered automatically and watches for changes in the input value. Since it's just a dummy query, you could trigger an update state event on failure. Either way, it is a bit cumbersome to implement, so if your current solution is already working that may be the best fit


Thanks @Tess , do you think that a feature could be added to retool where changing the inputs to a module is its own distinct event?

Hi @webster! I believe we are working on a more long-term project for automatic javascript queries; it sounds like this might simplify your workflow a bit. I'm not sure on the timeline for that project, but it's something to be on the lookout for. As for your original request, yes, I don't believe we have a module input change event project on our roadmap yet, but I can submit a feature request.