What if you need to manage more complex states? Here useReducers comes into play
React Hooks are so powerful and especially some additional hooks.
Do you know there is an alternative to useState called useReducer hook? It is used to manage more complex states.
Let's look into detail π§΅ππ»

What if you need to manage more complex states? Here useReducers comes into play

The second value is a dispatch function using which we can update our state.
Here is the complete syntax ππ»

I just implemented a basic code here. Basically, I am calling dispatch function on button click which will eventually call reducer function

Before that one thing to note here is that useReducer is for handling more complex states hence it is recommended to passing the current state as an object

Something like this ππ»

Play around with it here: https://t.co/6BlaBeul1U
Here is "payload" comes into play. It is used to pass the value which represents the payloads of the action.
For example, suppose I want to pass "temp" variable ππ»
https://t.co/6BlaBeul1U

Check out the code and try to play around with it for better understanding.
https://t.co/TCPEn0W3Pz
Check it out: https://t.co/nt4hZzInIR
More from Pratham
7 amazing websites that will help you improve your CSS skills
π§΅π
1οΈβ£ Learn to code HTML and CSS
- Learn how to build beautiful and intuitive websites by way of clear and organized lessons
ποΈ https://t.co/bl2rx2q8vk
2οΈβ£ CSS reference
- CSS Reference is a free visual guide to CSS. It features the most popular properties, and explains them with illustrated and animated content
ποΈ https://t.co/XAlj33g1Zk
3οΈβ£ CSS tutorial
- These tutorials on web design & CSS makes learning this stuff fun and easy
ποΈ https://t.co/y9vAj6fMGk
4οΈβ£ CSS Layouts
- This site teaches the CSS fundamentals that are used in any website's layout.
ποΈ https://t.co/n4EGLScpDF
π§΅π
1οΈβ£ Learn to code HTML and CSS
- Learn how to build beautiful and intuitive websites by way of clear and organized lessons
ποΈ https://t.co/bl2rx2q8vk

2οΈβ£ CSS reference
- CSS Reference is a free visual guide to CSS. It features the most popular properties, and explains them with illustrated and animated content
ποΈ https://t.co/XAlj33g1Zk

3οΈβ£ CSS tutorial
- These tutorials on web design & CSS makes learning this stuff fun and easy
ποΈ https://t.co/y9vAj6fMGk

4οΈβ£ CSS Layouts
- This site teaches the CSS fundamentals that are used in any website's layout.
ποΈ https://t.co/n4EGLScpDF

5 amazing GitHub repositories for every self taught developer
A Thread π§΅
1οΈβ£ Computer Science
π Path to a free self-taught education in Computer Science!
π https://t.co/67jB5zqIes
2οΈβ£ Free Certifications
Curated list of free courses & certifications
π https://t.co/4XtlAVlovs
3οΈβ£ Free Programming Books
π Freely available programming books
π https://t.co/eOWLCtwtIV
4οΈβ£ JavaScript Question
A long list of (advanced) JavaScript questions, and their explanations β¨
π https://t.co/UvEl1Esvh3
A Thread π§΅
1οΈβ£ Computer Science
π Path to a free self-taught education in Computer Science!
π https://t.co/67jB5zqIes

2οΈβ£ Free Certifications
Curated list of free courses & certifications
π https://t.co/4XtlAVlovs

3οΈβ£ Free Programming Books
π Freely available programming books
π https://t.co/eOWLCtwtIV

4οΈβ£ JavaScript Question
A long list of (advanced) JavaScript questions, and their explanations β¨
π https://t.co/UvEl1Esvh3

Five free VS Code extensions that will change the way you do web development:
1. RapidAPI Client
Fulfill all your need for API development.
β’ Test and consume APIs
β’ Work with your VS Code theme
β’ Generate TypeScript, Swift, and Python interfaces from responses.
π https://t.co/FR0QhyTi8v
2. Better Comments
Create more human-friendly comments in your code.
β’ Alerts
β’ Queries
β’ TODOs
β’ Highlights
π https://t.co/AV2BwAMAlL
3. Git Graph
View a Git Graph of your repository and efficiently perform Git actions from the graph.
π https://t.co/S5wagmTgsa
4. Peacock
Do you have a habit of keeping multiple VS Code windows open?
Peacock lets you change the color of your VS code even if multiple instances are open.
π https://t.co/bmidPkTQOK
1. RapidAPI Client
Fulfill all your need for API development.
β’ Test and consume APIs
β’ Work with your VS Code theme
β’ Generate TypeScript, Swift, and Python interfaces from responses.
π https://t.co/FR0QhyTi8v

2. Better Comments
Create more human-friendly comments in your code.
β’ Alerts
β’ Queries
β’ TODOs
β’ Highlights
π https://t.co/AV2BwAMAlL

3. Git Graph
View a Git Graph of your repository and efficiently perform Git actions from the graph.
π https://t.co/S5wagmTgsa

4. Peacock
Do you have a habit of keeping multiple VS Code windows open?
Peacock lets you change the color of your VS code even if multiple instances are open.
π https://t.co/bmidPkTQOK

5 great code snippet websites for every web developer and designer
π§΅ππ»
1οΈβ£ 30 Seconds of Code
- Short code snippets for all your development needs
π https://t.co/91L4bAxkgF
2οΈβ£ Free Frontend
- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles
π https://t.co/2sIAm73EdZ
3οΈβ£ Little Snippets
- A free collection of HTML and CSS code snippets
π https://t.co/qxAyA2wA6U
4οΈβ£ CSS Deck
- Collection of Awesome CSS and JS Creations to help out frontend developers and designers.
π https://t.co/LcZYnipvCy
π§΅ππ»

1οΈβ£ 30 Seconds of Code
- Short code snippets for all your development needs
π https://t.co/91L4bAxkgF

2οΈβ£ Free Frontend
- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles
π https://t.co/2sIAm73EdZ

3οΈβ£ Little Snippets
- A free collection of HTML and CSS code snippets
π https://t.co/qxAyA2wA6U

4οΈβ£ CSS Deck
- Collection of Awesome CSS and JS Creations to help out frontend developers and designers.
π https://t.co/LcZYnipvCy
