In order to get a better understanding of how Hooks work internally, we are going to reimplement the useState Hook from scratch. However, we are not going to implement it as an actual React Hook, but as a simple JavaScript function—just to get an idea of what Hooks are actually doing.
Please note that this reimplementation is not exactly how React Hooks work internally. The actual implementation is similar, and thus, it has similar constraints. However, the real implementation is much more complicated than what we will be implementing here.
We are now going to start reimplementing the State Hook:
- First, we copy the code from chapter1_2, where we are going to replace the current useState Hook with our own implementation.
- Open src/App.js and remove the import of the Hook by removing the following line:
import React, { useState } from...