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
0
votes
0 answers
Dispatch is not saving data in data layer in React Context API
I'm following a tutorial where they are making a clone of Spotify. And to avoid prop-drilling I'm using React Context-API to save and pull user data for that I first tried to get the user and token but in the console, I keep getting the error…

Utsav Savani
- 1
- 1
0
votes
2 answers
useReducer with useContext results with Typescript error
I'm trying to create a context that holds state and reducer.
But it gives me error messages on the return statement and I just don't know what to do:
Operator '<' cannot be applied to types 'boolean' and 'RegExp'.ts(2365)
Unterminated regular…

sjiamnocna
- 167
- 1
- 11
0
votes
1 answer
React.js useReducer hook - No overload matches this call
I have a counter like this :
import { useReducer } from 'react';
type CounterState = {
count: number;
};
type UpdateAction = {
type: 'increment' | 'decrement';
payload: number;
};
type ResetAction = {
type: 'reset';
};
type CounterAction…

marc
- 119
- 8
0
votes
0 answers
Possible typing error in useReducer causes Array not to be identified as Array
I developed a simple ToDo application using React and Typescript. It works perfectly fine in the development environment and also in the preview version made available by Vite after the build, but when I upload that same application to Vercel, the…

KernelDN
- 17
- 6
0
votes
0 answers
No overload matches this call on useReducer function
I am getting the error on my useReducer function.
No overload matches this call.
Overload 1 of 5, '(reducer: ReducerWithoutAction, initializerArg: any, initializer?: undefined): [any, DispatchWithoutAction]', gave the following error.
Argument of…

chucknor
- 837
- 2
- 18
- 33
0
votes
0 answers
Component not rendering update UI after state change by using useReducer hook and context api
My ProductList Component which is used to show filtered products
const ProductsList = () => {
const { cate } = useParams();
const { getFilterProducts, all_products, filter_products } = useFilterContext();
const [loading, setLoading] =…

Prince Singh
- 87
- 6
0
votes
0 answers
how to use useReducer handling visibility for 9 comboboxes
I'm trying to get a useReducer to make visible/hide 9 different comboboxes when they click a plus or minus button. I have it working withuseState but a co-worker said to use useReducer instead but I can't figure out how to make it work. The idea…

NewbieCoder
- 75
- 1
- 8
0
votes
1 answer
Iam making a Todo using (useReducer and useContext) but the update functionality is not working please check this out
This is my App.jsx , where iam displaying all the todos, after clicking edit the input gets the value of selected todo and while changing the value and clicking on update it does nothing.
export default function App() {
const { dispatch, state } =…

Bipin Bhandari
- 1
- 2
0
votes
0 answers
Problem with converting Promise in useReducer - typescript(react JS)
Convert Promise to data
I am trying to convert my use state to use reducer.
an async function is calling to fetch data and I'm not abale to use it in the reducer
here is part of the code:
switch (action.type) {
case "load":
…

Amir Esf
- 1
- 1
0
votes
1 answer
How to remove an element from array, that array is a state of useReducer
I have a cart array of carted products. Now i want remove a product using useReducer. I can add products to the cart. But I am not getting the how will i remove that product from the cart. The cart array is a array of object evey obecjt is a product…

Dipto Roy
- 23
- 3
0
votes
0 answers
How to use SWR with useReducer
I have useReducer and I have action type for fetching data inside useEffect and dispatch it like this.
function reducer(state, action) {
switch (action.type) {
case 'FETCH_REQUEST':
return { ...state, loading: true,…

Random People
- 39
- 5
0
votes
0 answers
React formReducer in context causing rerender with each keystroke
I am trying to architecture a React form which uses functions and data from context.
I have a formReducer which is used by one of the context state values.
export const FormContext = createContext({});
function formReducer(state, event) {
if…

tdammon
- 610
- 2
- 13
- 39
0
votes
1 answer
the useReducer dispatch is not called in a callback
I hope someone can help me with that. I'm experience the following using the React useReducer:
I need to search for items in a list.
I'm setting up a global state with a context:
Context
const defaultContext = [itemsInitialState, (action:…

andrixb
- 121
- 1
- 10
0
votes
1 answer
How to use useReducer with createContext?
I am learning how to create a React reducer to be used in a React context.
Can someone explain why the instructor created the {currentUser: null} object twice? Once in the context (line 7), once as an INITIAL_STATE to be used in the reducer (lines…

chu-js
- 181
- 7
0
votes
0 answers
undesirable action is getting fired in useReducer hook even though correct action has been specified
I am creating a calculator app, in which I have attached the ADD_DIGIT action to the decimal button and the CHOOSE_OPERATION action is added to operators.
I want the user can add decimal only once and I am using this condition inside ADD_DIGIT…

Apoorv Sharma
- 5
- 3