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.
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...