Skip to main content
This page shows how to interact with the application state. In particular, you will learn how to:
The snippets in this page work with the Atoti UI starter. If you have not installed it yet, then read Setup.
Atoti uses Redux for state management. A basic understanding of it is preferable in order to understand what follows.
Consuming and updating the state is possible using two hooks: useSelector and useDispatch from react-redux. It works just like when you use Redux to manage the state of any web application. The only difference is that you do not have to create and provide a store, as Atoti UI does it for you. See more details and examples below.

Consume state attributes

To retrieve attributes from the state, use useSelector. For instance, the following snippet implements a higher order component which depends on isPresenting. If it is true, then it just displays the application, but if it is false, then it also displays a custom horizontal application bar to the left of it.
It can then be registered as follows, in your index.tsx:
Like getIsPresenting in the example above, more selectors are exported from @activeviam/atoti-ui-sdk and allow you to retrieve specific pieces of state:

Trigger state updates

To update the state, use useDispatch. For instance, the following snippet implements an application menu item which adds a new empty page to the dashboard each time the user clicks it.
This menu item can be added into the Edit menu as follows, in your index.tsx:
For more information about the actions you can dispatch in order to update the state, see Action.

Advanced use cases

For more advanced use cases such as extending the state or changing the initial state, you can use a tool called a store enhancer. Store enhancers allow to hook into the application’s Redux store creation. They can be passed through Configuration, in your index.tsx:

Extend the state

What if you need to share state (that is not part of the core Atoti UI state) between several components? With the right store enhancer, your own state can live along the core state, within the Atoti UI store. For instance, the following store enhancer introduces a boolean attribute called foo along with an action to toggle it. It allows your components to use useSelector and useDispatch in order to consume and update this slice of state.

Change the initial state

You can configure the initial state by overriding the Redux preloaded state. For instance, the following store enhancer makes Atoti start up in presentation mode:
Don’t forget to forward preloadedState, as illustrated in the snippet above. Forgetting it can break other store enhancers, possibly registered by other Atoti UI extensions.