Why you need hooks and project | Chai aur react tutorial #5 Summary
This is the summary of video based on what i have learnt from this video
In this video titled "Why We Need to Use Hooks and Project", I explored a very interesting concept: understanding why we need to use Hooks in React, not just how to use them.
Why Hooks Matter:
The instructor gave an interesting analogy to explain why knowing when to use something is important. He compared it to cricketers practicing different shots depending on the conditions of the pitch, such as playing a pull shot in Australia but focusing on straight drive shots and others when playing in Asia . Similarly, with Hooks, we need to understand the right scenario to use them.
To demonstrate, we built a simple counter app. The app had a number displayed on the screen with two buttons for incrementing and decrementing the value. However, when we tried to update the counter using a regular variable, the value changed in the console but didn’t update on the UI.
The React Solution:
This is where React and Hooks come into play! We learned that when a state changes in React, it needs to trigger a UI re-render. Without React’s useState hook, updating the UI manually for each element (especially if used in multiple places) would be a very tedious process.
Using useState, we were able to update the counter seamlessly across the UI. The app now re-renders every time the state changes, ensuring the counter is updated instantly wherever it's displayed.
Project Exercise:
As part of the learning process, I created a project where the counter increases and decreases using useState, but I added a twist: the counter doesn’t go above 20 or below 0. This was a fun little exercise to implement logic alongside Hooks.
That’s what I learned from this video about why Hooks are crucial in React and how they simplify state management in UI updates. Thanks for reading!