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
vote
2 answers
When using useReducer to control a form, do I pass the previous state on every action?
My form has two inputs:
username (type="text")
email (type="email")
I also have a .json file as a "database" to do some validation. The submit button can only be clicked if the user enters a username that doesn't exist on the .json file. The thing…

PeterO
- 31
- 6
1
vote
3 answers
Why don't you need to pass the state to the reducer with react useReducer hook?
If we look at the standard example of increment, decrement with useReducer hook:
const initialState = {count: 0};
function reducer(state, action) {
switch (action.type) {
case 'increment':
return {count: state.count + 1};
case…

jon
- 1,429
- 1
- 23
- 40
1
vote
1 answer
React how to add existing item to new state in reducer
I try to do Todo App, I stack on add existing pending task to completed task. How can i add existing item to new state in reducer or there is a another way to do that?
When i click the button which has completed id, i want to push that task to…

Yahya
- 11
- 1
1
vote
2 answers
Where to place dispatch function for useReducer and why?
I'm new to React and I'm currently learning about useReducer.
I've created a simple login feature that verifies if the user inputted email includes '@' and the password length is greater than 5.
If these two conditions are met, I want my program to…

Jasper
- 27
- 3
1
vote
1 answer
App redirect to root inside axios interceptor with reducer dispatch
My app have this structure.
I'm using a reducer atached in Axios to when axios do any API request my overlay show "loading" page. Its all ok when I not using routes. When I to do any API request inside a route I'm redirected to root route.
My…

Silvio
- 73
- 6
1
vote
2 answers
React - update state with timeout in reducer
Can anyone help me to update state with timeout in react reducer.
I don't have much experience even with pure javascript, so I can hardly find an answer myself at this moment.
In my first ever react app (with useContex and useReducer) i have simple…

ribosed
- 128
- 1
- 11
1
vote
1 answer
Can't update value using reducer React JS after click
I'm currently learning useReducer and try to convert useState to useReducer in todo app. My problem :
TOGGLE_TODO can't update the value when click.
// First try
case TOGGLE_TODO:
let targetId = todoItem[action.index];
let newTodo =…

Tom-Cat
- 73
- 1
- 7
1
vote
0 answers
React Calling function from other function, doesn't get the latest state value
I have a reducer to manipulate the Tableprops such as pagination, order, and filter. The TableProps will always updated everytime the is a change inside the table and its work fine. But when I call the delete function and then I call fetch function.…

Eugene Pranoto
- 11
- 2
1
vote
1 answer
Update parameters value between screens in react-native
in my 2 screens react-native app, I'd like to know which is the best way to do the following:
In the main screen, a simple Text component shows "Hello" and a button that leads to a screen that shows "Hello" in an input field and a "GoBack"…

Adriano Bellavita
- 143
- 1
- 3
- 12
1
vote
0 answers
How to fulfill React useEffect missing dependency requirements?
I can't figure out, how to fulfill the useEffect missing dependency requirements in the Dashboard component, where I only want to fetch Jobs once on render.
Adding fetchJobs as a dependency or removing the dependency array causes infinite…

suchislif3
- 11
- 2
1
vote
0 answers
How to update state with fetched data using useReducer
I am creating a calculator with React and facing issues with updating my state with fetched data. The result is fetched correctly, but the application crashes as it does not wait for async fetching opreration. Could someone assist how can I combine…

Daniel Ziomek
- 25
- 4
1
vote
1 answer
UseState or UseReducer to manage FormData
UseState or UseReducer to manage FormData
I have a question, for render formdata in react (for example login, register, contact form data) it's better usereducer or usestate?

zeltarave
- 23
- 6
1
vote
3 answers
How to make a delay in React
When you click on the button, another screen is rendered:

AdamParadox
- 13
- 1
- 4
1
vote
1 answer
React useReducer bug while updating state array
I haven't been in React for a while and now I am revising. Well I faced error and tried debugging it for about 2hours and couldn't find bug. Well, the main logic of program goes like this:
There is one main context with cart object.
Main property…

Nijaz
- 168
- 2
- 11
1
vote
1 answer
useReducer Dispatch called twice
Below is my code, whatever action i dispatch using the below reducer, dispatch is called twice. I have read that reducers must be pure functions and no side effects or api calls to be made from a reducer. Else this behaviour is expected. What am i…

Md Abdul Basith JH
- 11
- 2