For questions regarding the `useReducer` hook in React. `useReducer` is an alternative way to manage complex state by defining a reducer function that creates the next state based on the current state and a dispatched action.
Questions tagged [use-reducer]
495 questions
-1
votes
1 answer
React / MERN authentication - Uncaught TypeError: reducer is not a function at updateReducer (react-dom.development.js:16664:1)
I am working through The Net Ninja's MERN Authentication tutorial and running into the error "Uncaught TypeError: reducer is not a function" after I complete the signup form. The user gets saved to the mongo DB but I then get the four errors in the…

bwash70
- 1,135
- 2
- 11
- 24
-1
votes
1 answer
useReducer duplicates the added elements
Why are two elements added instead of one?
My codesandbox
I apologize for such a short description, but I do not know what else to add

i like Cola
- 277
- 6
- 15
-1
votes
2 answers
State is always undefined in nextjs useReducer and useContext
I am using context api in my nextjs project but whenever i am trying to get value from state using context api it is always throwing error "undefined"
AppReducer.js
const initialState = {
isMobile: false,
user: {},
};
export const…
user18052819
-1
votes
1 answer
updating two state in parallel without using useReducer
In this code when I click the delete button I get this error:
App.js:9 Uncaught TypeError: Cannot read properties of undefined (reading 'map')
I realized the reason is that I must update the state of selectedNumber before updating the numbers state.…

user3494434
- 53
- 7
-1
votes
1 answer
How to use useReducer hook with async data in React?
I'm trying to use the useReducer hook to fetch data from an API and then update state. Since this is a small project, I'm trying to avoid using useContext, and instead just passing the dispatch function down as props.
How I've done it before is…

robert theboss
- 101
- 4
- 13
-1
votes
1 answer
Dispatch action from componentWillUnmount()
I am creating a Multi part form as below,
I am trying to get FormPart1 value in Parent when clicking Button.
For this I am using dispatch from within componentWillUnmount() phase.
I this…
-1
votes
1 answer
React gives wrong index to Child with React.memo
I've got a problem in my project which is pretty large therefore I can't post every part of the code here, but I'll try to summarize the main parts.
I've got a parent component which state is managed through a useReducer and which render returns a…

Fsanna
- 347
- 1
- 4
- 11
-1
votes
1 answer
useReducer hook isn't working, how to solve it?
I've used useReducer hook in react. al of my code seems right but it isn't working. Here goes my code
import React, { useEffect, useReducer, useContext } from 'react';
import reducer from '../reducers/filter_reducer';
import { useProductsContext }…

Saimur Rahman
- 31
- 1
- 6
-1
votes
1 answer
text is used as a state variable but not declared
In the following example from docs on useReducer
The state variable text is used in
onChangeText={(text) => {
dispatch({ type: 'first', value: text })
}}
But as far as I can see it is not declared anywhere beforehand. Am I missing…

asif malik
- 1
- 4
-1
votes
1 answer
Is it possible to manage different switch cases in reducer function of useReducer hook on a single button?
I have a question "Make a “room” with a light that has 4 levels – off, low, medium, high – and change the level
each time you press a button. Create a second button to turn the lights off."
I'm assuming that I need to manage three levels i.e. low,…

Rija Shaheed
- 69
- 2
- 7
-1
votes
1 answer
Trying to convert into typescript..cant figure out how to make action types and payload..i am using useContext and use Reducer
Trying to convert into typescript..cant figure out how to make action types and payload..i am using useContext and use Reducer
i basically want my action to get types from the key of ./types that is provided and laso figure out the way to provide…

tanmay
- 39
- 1
- 8
-2
votes
2 answers
Why dispatch(actionObject) is called inside a anonymous arrow function?
Below is a simple ToDo-List Code by using useReducer().
I am trying to toggle the check box. Although Code is working
concept wise I am not able to understand why dispatch function is being called inside an anonymous arrow function ?
import…

Nagesh Singh
- 59
- 4
-2
votes
1 answer
Just trying to figure out the best practice in using useReducer + context hooks
Just trying to figure out the best practice in using useReducer + context hooks.
Which is better practice?
Have one useReducer in the provider. ( 1 giant initial state + multiple combined reducers )
Have multiple useReducers in the provider each…
-3
votes
3 answers
reactjs ---> useReducer topic
in the reactjs I am not understand the below code please help me in this
...todo, complete: !todo.complete
according to me first ...todo is the spread array, and after comma the condition has been implemented on it.