Goal: I'm building an app in Retool and need to dynamically update multiple temporary state variables based on button clicks. I have a table (table1
) displaying data fetched from a query (getCourses
), and I want to add selected rows from this table to different temporary state variables (tempState1
, tempState2
, tempState3
, tempState4
) using buttons. The expected behavior is for each button to add the selected row’s data to the respective state variable.
Steps:
- Created four temporary state variables (
tempState1
,tempState2
,tempState3
,tempState4
) initialized as empty arrays. - Added a table (
table1
) that displays data from thegetCourses
query. - Added four buttons to handle the addition of selected rows to each state variable.
- Configured the click handlers for the buttons to concatenate the selected row's data to the existing data in the respective state variable.
Details: I'm encountering an issue where the concat
method is not functioning as expected, possibly due to the initial state not being set correctly as an array. Below is an example configuration for one of the buttons:
- Action: Set variable
- State:
tempState1
- Method: Set in
- Key path: Leave it blank
- Value:
{{ tempState1 ? tempState1.concat([{ $ref: `/courses/${table1.selectedRow.data.id}` }]) : [{ $ref: `/courses/${table1.selectedRow.data.id}` }] }}