React Hooks
React Hooks
Key Points :
Examples :
❖ Instagram Likes When you double-tap a post, it shows a heart ( ❤️) and
the number of likes increases by 1
State: Keeps track of how many likes a post has.
❖ E-commerce App : When you select a size for a shirt (e.g., Medium), the
app highlights it.
State: Tracks which size you selected.
Introduction to Hooks
Hooks are Javascript functions that let you use React features (like state
and lifecycle methods) in functional components.
Functions starting with use are called Hooks.
Key Points :
1. Call Hooks at the Top Level:Use hooks only at the top of your
functional component or custom hook & Do not call hooks inside loops,
conditions, or nested functions
2. Call Hooks in the Same Order:Always call hooks in the same order on
every render to avoid errors.
Parameters :
REDUCER :
UseReducer
Real-World Analogy Example: Bank Account :
1. Deposits money.
2. Withdraws money.
3. Checks balance.
Example :
If you want to add a new todo,remove a todo you need to tell
the reducer what to add or remove That "what" is your payload