Manage global state with React hooks.

Charles Stover
6 min readNov 5, 2018

Since the announcement of experimental Hooks in React 16.7, they have taken the React community by storm.

Unfortunately, the same way class components only manage local state, the built-in useState React hook only manages local state in functional components. Global state management is still left to higher-order components and community-contributed endeavors.

The reactn package, while also targeting class components, offers a React hook for accessing and managing global state in functional components. The ReactN package intends to integrate global state into React as if it were native functionality. In contrast to libraries like MobX and Redux, which are state-first solutions to state management, ReactN aims to be a React-first solution to global state management.

To read more about or contribute to the ReactN project, the GitHub repository is welcoming to the community. To install ReactN, use npm install reactn or yarn add reactn.

A useState Overview 🏁

Analogous to the built-in React hook useState, the useGlobal hook of reactn behaves as similar as possible, with a few key differences. To clearly identify these differences, I’ll first provide useState’s behavior.

--

--

Charles Stover
Charles Stover

Written by Charles Stover

Staff+ front end engineer | Tech lead | Architect | quisi.do

Responses (14)