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
5 amazing websites that will blow the mind of a developer. Definitely check them out
🧵👇🏻
1️⃣ Animation generator
- Dead simple visual tools to help you generate CSS for your projects.
🔗 https://t.co/IFmIEgDiVY
2️⃣ Neural Network Visualizer
- Deep playground is an interactive visualization of neural networks, written in TypeScript using d3.js.
🔗 https://t.co/mTAlFbJsOW
3️⃣ Blockchain Demo
- A visual demo of blockchain technology
🔗 https://t.co/I1RwxYcM1Z
4️⃣ Developer Roadmaps
- Step by step guides and paths to learn different tools or technologies
🔗 https://t.co/VSNPdG8jQR
🧵👇🏻
1️⃣ Animation generator
- Dead simple visual tools to help you generate CSS for your projects.
🔗 https://t.co/IFmIEgDiVY
2️⃣ Neural Network Visualizer
- Deep playground is an interactive visualization of neural networks, written in TypeScript using d3.js.
🔗 https://t.co/mTAlFbJsOW
3️⃣ Blockchain Demo
- A visual demo of blockchain technology
🔗 https://t.co/I1RwxYcM1Z
4️⃣ Developer Roadmaps
- Step by step guides and paths to learn different tools or technologies
🔗 https://t.co/VSNPdG8jQR
9 websites that will help you learn web development faster (they are free) 🧵
1. How HTTP Works
Everything you need to know about HTTP based system.
🔗 https://t.co/gVZS4RzS1a
2. 30 Days of Node
Learn Node step by step with interactive examples and code snippet in 30 days.
🔗 https://t.co/9nbtMiNB1C
3. How DNS Works
Learn what happens when you type a website address in your browser
🔗 https://t.co/SqMRNnDbc3
4. Git
Check out this excellent free website to learn git visually.
🔗 https://t.co/rQJMISBDfS
1. How HTTP Works
Everything you need to know about HTTP based system.
🔗 https://t.co/gVZS4RzS1a
2. 30 Days of Node
Learn Node step by step with interactive examples and code snippet in 30 days.
🔗 https://t.co/9nbtMiNB1C
3. How DNS Works
Learn what happens when you type a website address in your browser
🔗 https://t.co/SqMRNnDbc3
4. Git
Check out this excellent free website to learn git visually.
🔗 https://t.co/rQJMISBDfS
Six tools that will change the way your write code: 🧵
1️⃣ HarperDB
Deciding between SQL and NoSQL? Use HarperDB as it provides you the functionality of both.
Access data using API endpoint.
🔗 https://t.co/qf5CalexfA
2️⃣ Visual Go
Visualizing data structures and algorithms
🔗 https://t.co/b8YeMYdOaf
3️⃣ Extends Class
Syntax validators, code formatter, testers, HTTP clients, mock server, and much more.
🔗 https://t.co/GlKjoBnzqg
4️⃣ Codeshare
Share Code in Real-time with Developers. An online editor for teaching and interviewing.
🔗 https://t.co/2m1Ne3KJRK
1️⃣ HarperDB
Deciding between SQL and NoSQL? Use HarperDB as it provides you the functionality of both.
Access data using API endpoint.
🔗 https://t.co/qf5CalexfA
2️⃣ Visual Go
Visualizing data structures and algorithms
🔗 https://t.co/b8YeMYdOaf
3️⃣ Extends Class
Syntax validators, code formatter, testers, HTTP clients, mock server, and much more.
🔗 https://t.co/GlKjoBnzqg
4️⃣ Codeshare
Share Code in Real-time with Developers. An online editor for teaching and interviewing.
🔗 https://t.co/2m1Ne3KJRK