Let's Build React Context From Scratch in JS
summary
Builds a minimal React-like Context API in plain JavaScript using closures and the language's synchronous blocking behavior, implements createContext/useContext by returning a provider/consumer pair that sets and reads a module-scoped currentValue, handles nested describes, and fits in about 10 lines of JavaScript. Shows the failure mode with async code, explains fixes via bound closures and Node's async local storage / async hooks, and mentions a published npm package named "context" that mirrors this approach.
AI-written summary · about
chapters (7)
- 0:00Introduction and speaker
- 3:13Building a unit test library
- 7:25React Context inspiration
- 10:16Implementing context from scratch
- 16:21Fixing context leakage
- 18:51Limitations and async code
- 19:57Conclusion and package promotion
related talks
27mLet's Build React Context From Scratch in JS
06mContext in React
12mContext with React 19
17mLearn how to use the React Context API
31mAll about Context API
35mHandling Large-Scale State Management with Context and Hooks
22mPowering Code Reuse with Context and Render Props
10mGet Rich Quick With React Context
