docs/versioned_docs/version-3.0.0-LTS/app-builder/anti-patterns.md
When building applications with ToolJet, it's essential to follow best practices to ensure your apps are efficient, maintainable, and provide a smooth user experience. This documentation outlines common anti-patterns to avoid while using ToolJet and offers solutions to optimize your applications.
Promise.all and setTimeout in the Run JavaScript code query when an accurate isLoading state is needed.Example:
You have a Table displaying data from {{page.variables.data}} and a Save Changes button that updates the data. When users edit rows and click Save Changes, you might initially implement the update like this:
const data = page.variables.data;
Object.values(components.table1.dataUpdates).forEach(ele => {
data[ele.id] = ele;
actions.setPageVariable("data", data);
});
The setPageVariable action is executed inside the loop for each row update. This causes the table to re-render every time the variable is updated, leading to significant performance degradation, especially when multiple rows or cells are updated simultaneously.
const data = page.variables.data;
Object.values(components.table1.dataUpdates).forEach(ele => {
data[ele.id] = ele;
});
actions.setPageVariable("data", data);
queries.getEmployees.data = [].run-py1 or my query.{{queries['run-py1'].isLoading}}).Avoiding these anti-patterns when using ToolJet ensures that your applications are efficient, responsive, and maintainable. By following these best practices, you can enhance user experience and simplify app management. Always consider the impact of your development choices on both performance and scalability.