Let's expand the power of functional components and questions like Why Hooks? What do they solve?
In this section, we'll look at the over-arching concepts of functional components along with hooks. Because some of topics in this section could be courses in and of themselves, we won't go too in depth on them, but check out the links below to dive deeper into Composition and Closures.
You might be wondering, "What do hooks solve?". . .
✅ Allow people to trade off class-based components for functional ones.
✅ In doing so, developers no longer need to spend time working with the confusion of class scope and the 'this' keyword.
Another coding concept that hooks use is composition.
✅ Where you take small, stand-alone functions to build more-complex functions.
✅ This is useful because you can test smaller segments for reliability as well as to reuse small blocks of code to create different functions.
✅ This pattern is very robust and flexible.
✅ You can compose React hooks to create custom hooks, plus hooks have many additional uses as well.
✅ With these building blocks, you can build over-arching features with reusable hooks.
Closures are yet another piece of JavaScript technique used in hooks. We won't go into closures too much in this course, but look through the resources below to at least get a working understanding.
Curry and Function Composition
Functional Programming in Javascript: How and Why