appsmith-docs
appsmith-docs copied to clipboard
[Docs]: Provide best practices in using Widget's selectedValue property or pass parameters to the Query/API as alternative to storeValue
Is there an existing issue for this?
- [X] I have searched the existing issues
Documentation Link
https://docs.appsmith.com/reference/appsmith-framework/query-object
Discord/slack/intercom Link
No response
Describe the problem
Many users use the storeValue function unnecessarily in many places. There have been scenarios where when a widget like Select button is updated, they call the storeValue function in onOptionChange first, and then immediately run an API that is using the stored value. storeValue is an expensive function and needs to be used only when needed. It would also take time, so calling an API immediately after would not have the latest value of the store updated by then. You would have to correctly use async/await to avoid running an API/Query with outdated values.
And most likely they wouldn't be needing the stored value for any other case except to run the Query whenever a CTA is triggered.
Describe the improvement
This can clearly be avoided by educating the user to directly use the widget's selected value. Eg JSObject1.formData.id or Select1.selectedOptionValue or DatePicker1.formattedData, etc
Another way to do it, would be to retrieve these values from the above mentioned widgets and pass it as a query-object to the API/Query. This can be accessed inside the queries as this.params, hence allowing the API to be generic without being dependant on any specific widget value.
Any app that is using storeValue function this way to achieve these workflows, would most likely have a lot of them. And the performance of the app can increase significantly by using the above mentioned alternatives wherever possible.
We'll add this to a page called Best Practices under the Build Apps section