Custom States
Last updated
Last updated
A custom state is an arbitrary container capable of holding any type of data (single or list) that is readily available to the user in the current browser session.
It doesn't matter where you create the custom state (or how), as long as you keep in mind that when you add it inside a cell of a repeating group or inside a reusable element, you cannot access it through a normal 'set state' action.
Custom states have two major use cases:
Storing temporary data on the page
Navigation
Remember Custom states will not store the data you have saved if you reload the page.
In the example below, based on the pre-build admin page that you will find in the template, we want to select multiple users in a list and perform a bulk action on those selected users.
When the user clicks the checkbox for selecting a user in the table, we add this user to our custom state list of users which we created previously.
We can then send the list of users from the ⚡️selectedUsers to the backend workflows to delete them.
Make sure that the custom state is of the type you want to work with and the 'is a list' checkbox is checked.
If you work with set of data that has be pre-loaded on a page it's better to use Repeating Group element rather than a custom state as a list.
For example imaging we have a field called ' Permissions' on the User data type. If you would like to display list of Permission on page load for that User via state would have to set that values on the page load since you cannot set default values of a state if it's a list or custom datatype.
If you have more then one custom state list or custom state field where data needs to always be available on page load, the 'Page is loaded' can quickly become bulky with 'Set state' action, especially if you have multiple elements where you want to set the state.
It's much better to work with repeating groups when it comes to lists. On the page load, you do not have to worry about setting the state of the list as it will automatically pre-populate since it's a repeating group. You can structure your repeating groups in the Source popup or use the Repeating group in which you display the data.
Additionally manipulating the list in the Repeating group is as easy as manipulating the custom state with the 'Display list in a repeating group' action.