Summary
In this chapter, we started out by reimplementing the useState
function, making use of global state and closures. We then learned that in order to support multiple Hooks, we need to keep track of them using an array. By using a state array, however, we were forced to keep the order of Hooks consistent across function calls. This limitation made conditional Hooks and Hooks in loops impossible. We then learned about potential alternatives to the Hook API, their trade-offs, and why the final API was chosen. Finally, we learned how to solve the common problems that stem from the limitations of Hooks. We now have a solid understanding of the inner workings and limitations of Hooks. Along the way, we also learned about the State Hook in depth.
In the next chapter, we are going to create a blog application using the State Hook and learn how to combine multiple Hooks.