JavaScript API methods for managing temporary state.
Methods
Use temporary state methods to temporarily store data within a Retool app.
temporaryState.setIn()
Sets the value of temporaryState
at a specified location. The initial value of temporaryState
must be an empty object (e.g., { }
).
Syntax
temporaryState.setIn(path, value)
path required
An array of keys or indexes to select, where each item represents a key or index in the path to the object to update.
value required
A string, object, boolean, number, or array to set as the value at the path.
Return value
Returns a void Promise when the method resolves.
Example
Set the second item of key1
, nested in object1
in tempState
, to value2
.
await tempState.setIn(["object1", "key1", 1], "value2");
temporaryState.setValue()
Sets the value of a temporary state variable.
Syntax
temporaryState.setValue(value)
value required
A string, object, boolean, number, or array to set as the value of the temporary state object.
Return value
Returns a void Promise when the method resolves.
Example
Set the value of tempState
to the sorting method used on usersTable
.
await tempState.setValue(usersTable.sort);