How ReactN hacks React Context

Getting Context value without using Context

Charles Stover


Some of you may be familiar with ReactN, a boilerplate-free global state management solution for React applications. In an attempt to solve common complaints by developers about other global state packages, the driving design principle behind ReactN is “What if global state were built into React?” All features attempt to mimic React’s design decisions, giving the illusion they are a part of the React core.

This article covers an edge case feature implementation. The way this feature is implemented is unlikely to ever be beneficial to you personally. The purpose of this article is to share what was learned, offer eager developers insight into how a complex problem was solved, discuss design decisions, and engage the community in discussion around those decisions.

What’s the feature? 🐛

Last weekend, ReactN launched 1.0, denoted by the highly demanded feature of Context support. Developers who were concurrently rendering their applications had the issue that the global state was shared across each instance. Now, a <ContextProvider> can wrap any or all of a React application, and a new instance of a global state is limited to the scope of that Context. At the same time, developers can now use Provider1.useGlobal and…