Questions tagged [use-reducer]

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.

495 questions
0
votes
1 answer

localstorage is not defined in Next js to use in useReducer

I'm having a problem accessing to localstorage in third argument of useReducer as lazy-initial to get shopping cart items from localstorage. Can anyone help with with this please? I need to access localstorage so that shopping cart which is…
0
votes
1 answer

state return by useReducer doesn't change when init value change

dishState return by useReducer doesn't change even though initDishState change. Is it caused by asynchronous process which makes the variable mutated somewhere ? export default function DishModal({ type, itemCode, modalRef, initDishState, …
UMR
  • 310
  • 4
  • 16
0
votes
1 answer

Toggling todo completed flag with use Reducer

I tried to convert my react-todo app from useState to useReducer , I made most of functionalities but toggling completed flag in my todos. I tried any possible solution but I couldn't solve it , please help me on this. what should I write in…
muller
  • 41
  • 8
0
votes
1 answer

How to use localStorage with useReducer hook?

I have a todo-app,created with useReducer and I need to save them to localStorage, but I got an error.What might be wrong here? const [{ todos, todoCount }, dispatch] = useReducer( reducer, { todos: [], todoCount: 0 }, …
adizh
  • 13
  • 4
0
votes
1 answer

Correct way to update a state inside useReducer (React.js)

I have two 'select' inputs (html) that work togueter to display info, this is the state: const [foodValues, setFoodValues] = useState({ type: 'Everything', category: 'Everything' }) Everything works just fine, I'm using a classic handleChange() on…
cmJericho
  • 13
  • 3
0
votes
2 answers

How do I call an object inside useReducer?

So I have a simple form with two inputs, and the idea is that when you fill in the form and click enter it shows you on the screen the info you typed in. I managed to do this with one input, but now when I want to try it with an object I'm getting…
FraneCal
  • 69
  • 8
0
votes
1 answer

How to update a single object inside the array with useReduce on state change

I have a checkbox component and when a value is selected for a checkbox, I want to update my state with true and false values. In total I have 5 different states.I cannot update the single object from my state. Can someone help? With the current…
wolf
  • 399
  • 1
  • 6
  • 19
0
votes
1 answer

UI not updating after userReducer changes state

I`m trying to use a reducer function to update state. I have a state variable, phones, which is an array of phone objects. When the user clicks a button, I want the quantity property of the phone object to increase. Quantity does get increased, but…
Ben
  • 17
  • 1
  • 4
0
votes
1 answer

Gettin 'null' while fetching data from api with React Context

I'm trying to get a bunch of articles from API using axios and useContext hook in React, but getting 'null' as a response. This is the code from "State" file import React, { useReducer } from "react"; import axios from "axios"; import ArticleContext…
Vahe
  • 99
  • 1
  • 3
  • 12
0
votes
1 answer

Cannot access object values from useContext. Using useReducer and useContext for State Management

I'm trying to access my dispatch functions as well as my states from the useContext. Weird thing is, when I try to deconstruct the context object (so I can access them directly), it tells me it doesn't exist (error Msg: Property 'authDispatch' does…
Jae
  • 86
  • 1
  • 11
0
votes
1 answer

Redux useReducer and mapDispatchToProps not working

I'm building a react app using redux for state management. Inside the SearchField component I am using useReducer for handle the search field inputs (cityField and countryField). When i submit the fetchData function runs and sends a request to an…
Saverio Randazzo
  • 217
  • 1
  • 7
  • 19
0
votes
1 answer

can't console log state from reducer function?

I cannot figure out why the state isn't changing with this reducer function setup in React. I just want to console log the new state from the reducer function? const [lessonState, dispatchLesson] = useReducer(lessonReducer, { lesson: 0, …
lache
  • 608
  • 2
  • 12
  • 29
0
votes
2 answers

How manage global state using context API in React js

I am having issues managing the state of my navbar using useContext. Atm my app renders the menu items as soon as the menu toggle. I want this event to happen only onClick, also the button does not log the console.log message, it works only when I…
Leo
  • 481
  • 2
  • 9
  • 20
0
votes
0 answers

I keep getting [Unhandled promise rejection: Error: Request failed with status code 404] while deleting a post from my API in React Native

I just started coding and I tried to delete a post through my mongoDB API. The code that I used is pretty basic, my API requests all go through a reducer which is set up pretty clear. But when I try to delete a post from my DB, I get the error…
0
votes
1 answer

How to get react component with useReducer to rerender after axios call?

I am trying to learn state management with the useReducer hook so I have built a simple app that calls the pokeAPI. The app should display a random pokemon, and add more pokemons to the screen as the 'capture another' button is pressed. However, it…
Mac Bubb
  • 59
  • 1
  • 8