Skip to main content
Version: 1.0

useStateGlobal()

An useStateGlobal() represents main store in State-jet. It enables storing global data across React components without using a store.

function useStateGlobal<T>(
key: string,
initialValue?: T,
options?: { middleware?: Middleware<T>[], persist?: boolean, encrypt?: boolean }
)
  • key - A unique string used to identify the store.

  • initialValue - can store any data types (string, array, object)

  • options - An optional parameter which supports multiple options

    • middleware - which is used to add middleware support for state jet. Refer (Middlewares)
    • persist - if persist is true, the store data will be stored in localStorage. Refer (Persistence)
    • encrypt - supports encryption/decryption. Refer (Encryption)

    It returns the following properties:

    • set() – Updates the state data.
    • useStore() – Retrieves the latest state data.
    • undo() – Reverts the state to the previous value. Refer (Undo)
    • redo() – Restores the undone state. Refer (Redo)
    • clear() – Resets the state data. Refer (Clear)