Menu

Post image 1
Post image 2
1 / 2
0

React Hooks Explained: useReducer and useMemo for Beginners

DEV Community·Vinayagam·18 days ago
#ewsL0QIc
Reading 0:00
15s threshold

Introduction When I started learning React, I mostly used useState for everything. It worked well in the beginning, but as my project became a little bigger, managing state became confusing. I had multiple values, and sometimes one value depended on another. That is when I started learning about useReducer and useMemo. In this blog, I will explain both in a simple way based on my understanding as a beginner. useReducer useReducer is a React Hook used to manage state in a more structured way. Instead of directly updating state like in useState, we use a separate function called a reducer. This function decides how the state should change. The basic syntax looks like this: const [ state , dispatch ] = useReducer ( reducer , initialState ); Enter fullscreen mode Exit fullscreen mode Here, state stores the current value, and dispatch is used to send an action. The reducer function takes the current state and the action, and returns a new state.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More