Skip to main content

Global state

Creating and using global state

Create the state and use it within and outside a React component. Few lines of code. No boilerplate!


The state is created by hookstate. The first argument is the initial state value. The result value is an instance of State, which can be used directly to get and set the state value outside a React component.

When you need to use the state in a functional React component, pass the created state to useHookstate function and use the returned result in the component's logic. The returned result is an instance of State too, which must be used within a React component (during rendering or in effects) and/or it's children components.

Read more about hookstate and useHookstate in the API reference.