GlobalState
GlobalState in Shesha allows you to store and access shared state across your application.
Overview
GlobalState can be set or consumed by opening any codeEditor or js.
Setting GlobalState
To set a global state variable:
setGlobalState({ key: "hidden", data: true });
This uses key-value pairs — in this case, the key "hidden"
is assigned the value true
.
The data
value can be of any type, including booleans, objects, arrays, strings, and more.
Consuming GlobalState
To access a global state value:
globalState?.hidden;
By referencing the key on globalState
, you can retrieve the value that was previously set.
Benefits of GlobalState
- Simplicity – Easily set and access shared state across different components.
- Reusability – Use a single state variable in multiple places without prop drilling.
- Flexibility – Can store any type of value, including complex objects.
- Dynamic UI Control – Useful for controlling UI behavior, such as conditionally hiding or showing sub-forms based on state.
Tables
GlobalState can be used to access data from tables, such as indexTable -> tableData
.
Use Cases
- Calculations – Summing total values for specific columns.
- Index Access – Accessing values at specific indexes from table data.
- Selected Row – Accessing the selected row’s ID or data through global state.
Please note when the page is refreshed the global state is empty