@reactivers/hooks Github link@reactivers/hooks NPM link

useGlobalState

Introduction

  • useGlobalState provides a global state for you.
  • You can update the state globally.
  • All other components access your global state easily.
//Component A
const { globalState } = useGlobalState();

//Component B
const { setGlobalState } = useGlobalState();

Getting Started

  • You need to import useGlobalState and GlobalStateProvider.
  • useGlobalState reads data from GlobalStateProvider. So you need to wrap your entry component with GlobalStateProvider.
  • You may want to keep and read some data globally.

From Collection

import { useGlobalState, GlobalStateProvider } from "@reactivers/hooks";

From Package

import { useGlobalState, GlobalStateProvider } from "@reactivers/use-global-state";

Interfaces

Returns

interface IUseGlobalState {
    globalState: Record<string, any>;
    setGlobalState: any;
}

Example

Example Preview - CodeSandbox