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 🧵👇🏻

Usually, the useState hook is used to tackle states in React where you can pass the initial state and React preserves state for you between re-renders

What if you need to manage more complex states? Here useReducers comes into play
Similar to useState, the useReducer hook also returns a pair of values. Let's see what these two things are
The first value is `undefined` which is the current state (it is undefined because we didn't pass any initial state in the useReducer hook)

The second value is a dispatch function using which we can update our state.
The useReducer hook accepts 3 parameter

1. reducer
2. Initial state
3. init
Now we know that useReducer takes three parameters and return two values

Here is the complete syntax 👇🏻
Let's try to see this into action.

I just implemented a basic code here. Basically, I am calling dispatch function on button click which will eventually call reducer function
So far we haven't seen how the state can be managed using this.

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
Now we can simply update our state by passing the state parameter in the reducer function.

Something like this 👇🏻
Now every time I click on the button my state will be incremented by 1 because the reducer function returning the new state by adding one to the previous state.

Play around with it here: https://t.co/6BlaBeul1U
The reducer function accepts the second argument as well known as "action" using which we can tell the reducer function that what operations need to perform on the state.
Generally, we can pass different actions through dispatch to reducer via an object.
This is how you can pass different types of operations in the reducer function using the action parameter.
What if I want to pass some values through dispatch to the reducer function?

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
This may sound a little confusing for the first time. Don't worry I created a notes app for you using the useReducer hook.

Check out the code and try to play around with it for better understanding.

https://t.co/TCPEn0W3Pz
I have a video tutorial on YouTube explaining about useReducer in more bit details.

Check it out: https://t.co/nt4hZzInIR
That's pretty much it for this thread. If you like this thread, share it with your connections it means a lot to me 💖

Peace out 😉

More from Pratham

I've brought you some amazing GitHub repositories of web development tips and tricks 🌟

THREAD🧵🔽

1️⃣ JS Tips

- A huge list of 73 great tips and tricks of JavaScript

🔗
https://t.co/r0J9vW8WrH


2️⃣ CSS Protips

- A collection of tips to help take your CSS skills pro. Definitely check it out

🔗 https://t.co/5haB2xTWuz


3️⃣ JS Tips and Tricks

- Some advanced tips and tricks of JavaScript that can help you to take your skills onto next level

🔗 https://t.co/NvfoANwweV


4️⃣ Git Tips

- Git is an essential tool for very programmer. in this repo you'll find the most commonly used git tips and tricks

🔗 https://t.co/34qvOhYCZE
You can learn 90% of CSS using these 10 threads

🧵👇

1. All you need to know about CSS


2. Getting started with CSS animations


3. Z-index is tricky but this thread solve all your doubts


4. CSS positioning concepts
If you know CSS then you can use these amazing generators and save your time

Thread 🧵👇🏻

1️⃣ CSS Box Shadow Generator

- Generate CSS3 Box Shadow code for your Div, Frame, Buttons or any other HTML element with Outline, and Inset (inner) type shadow effects

🔗
https://t.co/6La36IzBLj


2️⃣ Glassmorphism

- Generate glassmorphic design easily

🔗 https://t.co/qrKqDV5tzY


3️⃣ Cool Backgrounds

- Explore a beautifully curated selection of cool backgrounds that you can add to your next project

🔗 https://t.co/df7VSaRSh9


4️⃣ Pixel art

- Create CSS pixel art, export the results to CSS and download them.

🔗 https://t.co/ojD8qwzuhx
Five great icons websites for every web developer and designer ⏺️

A Thread 🧵👇🏻


1️⃣ Icons 8

- Icons8 is just more than icons. You can download illustrations, vector images, music and much more

🖇️
https://t.co/inHse0QXBh


2️⃣ Icon Monstr

- Black and white themed minimal icons which looks super great. You can also cuatomize the thickness

🖇️ https://t.co/dbQrJi0IHf


3️⃣ Icon Icons

- Over one thousand free icons which you can download as icons or images

🖇️ https://t.co/h5NlH5fGGr


4️⃣ Icons finder

Filter through the world’s largest marketplace for icons with flexibility and ease. Made up by submissions from top designers around the world, and curated by the team

🖇️ https://t.co/sqiZ6H9sR7
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

You May Also Like

THE MEANING, SIGNIFICANCE AND HISTORY OF SWASTIK

The Swastik is a geometrical figure and an ancient religious icon. Swastik has been Sanatan Dharma’s symbol of auspiciousness – mangalya since time immemorial.


The name swastika comes from Sanskrit (Devanagari: स्वस्तिक, pronounced: swastik) &denotes “conducive to wellbeing or auspicious”.
The word Swastik has a definite etymological origin in Sanskrit. It is derived from the roots su – meaning “well or auspicious” & as meaning “being”.


"सु अस्ति येन तत स्वस्तिकं"
Swastik is de symbol through which everything auspicios occurs

Scholars believe word’s origin in Vedas,known as Swasti mantra;

"🕉स्वस्ति ना इन्द्रो वृधश्रवाहा
स्वस्ति ना पूषा विश्ववेदाहा
स्वस्तिनास्तरक्ष्यो अरिश्तनेमिही
स्वस्तिनो बृहस्पतिर्दधातु"


It translates to," O famed Indra, redeem us. O Pusha, the beholder of all knowledge, redeem us. Redeem us O Garudji, of limitless speed and O Bruhaspati, redeem us".

SWASTIK’s COSMIC ORIGIN

The Swastika represents the living creation in the whole Cosmos.


Hindu astronomers divide the ecliptic circle of cosmos in 27 divisions called
https://t.co/sLeuV1R2eQ this manner a cross forms in 4 directions in the celestial sky. At centre of this cross is Dhruva(Polestar). In a line from Dhruva, the stars known as Saptarishi can be observed.
Still wondering about this 🤔


save as q