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

Create higher order function for composing and using useReducer into another components gives me an error

I want to create a higher order function which contains useReducer hook as a singleton in order to composite with other components. But i got an error: Error: Invalid hook call. Hooks can only be called inside of the body of a function…
0
votes
1 answer

reducer case set value delayed response

When I dispatch "REMOVE_TODO" on button click it does what I want it to do, the problem I'm having is that when it executes. It doesn't return the correct current array length. Now when I click an item, it will dispatch "TOGGLE_TODO" which will…
0
votes
1 answer

how to change from useState to useReducer

The following code I am trying to convert it to useReducer but few things I am not able to figure it out. In the following code, handleClick updates the state and calls other functions for further actions. In useReducer, I can update the state but…
codejs
  • 141
  • 1
  • 10
0
votes
0 answers

Todo-list using useReducer and MongoDB - updating DB after Action of Reducer?

I tried connecting my Todolist with MongoDB to store my data. Since it is not recommended to fetch and update data within the reducer I'm a little confused on where to update the DB. My thoughts are whenever I change the List with an Action, I would…
0
votes
2 answers

Todo-List with useReducer and MongoDB - Error: „todo.map is not a function“

I tried setting up a simple Todolist using nodejs and a MongoDB. I also used useReducer to simplify all the actions and get a better understanding of it. I dont know where I went wrong but I get the error ‚todos.map is not a function‘. I guess it…
0
votes
1 answer

usereducer won't update state

I am very new to React and come across useReducer. If I paste my code here, it will be very long, because it involve component, useContext and useReducer.So I will paste some of the code only. I have question about the state in try and catch…
user2601660
  • 29
  • 10
0
votes
2 answers

React hooks - Dispatching a reset state from parent component

This is my application with the scenario reproduced, here the demo in codesandbox I have two components, Leagues ( parent ) and Details ( Child ). I have a implemented reset button example in the Details Component button which does const cleanArray…
Koala7
  • 1,340
  • 7
  • 41
  • 83
0
votes
1 answer

slowness in react native application

I recently created an application with react native in which I use Axios to request addresses of images from a database, the problem arises that on the main screen I made the request and through a map, I render a list of images and when moving to…
laura
  • 1
0
votes
1 answer

Uncaught TypeError: Object is not iterable when using useReducer with useContext for global store React js

I am trying to use hooks to replace the redux store with action and reducers I have created a global store using createContext and a global reducer using useReducer and trying to use the global state object with useContext in the below file which is…
0
votes
1 answer

the initialstate for use reducer isn't updating while using context api in react js

I am fairly new at using context API and hooks in react. am facing a problem that the initial state is not updating while trying to pass a dispatch of action using a reference of useReducer, eventhought the objects are passed to it. The code are as…
0
votes
1 answer

How to use useReducer in react-country-region-selector?

I used react-country-region-selector with useState, it worked well and updated the dropdown with my selection of country, code as follows: import React, { useState } from 'react'; const App = () => { const [country, setCountry] = useState(''); …
one-hand-octopus
  • 2,229
  • 1
  • 17
  • 51
0
votes
1 answer

Why is the onClick event triggering twice even though there's e.preventDefault using hooks in React?

Update: The problem is directly in the reducer and has nothing to do with the onClick function nor the deleteLastItem function. I tested this with console.logs and apparently the only one repeating twice is the one directly in the reducer. I was…
gxp2
  • 149
  • 2
  • 11
0
votes
1 answer

Reducer running twice when using useReducer and React Context API

I am kind of running my head into a wall on a weird circumstance using the React Context API along with the useReducer and useContext hooks. Here is my main store. import React, { createContext, useReducer } from 'react'; import { Reducers } from…
0
votes
1 answer

React Context - Post Like / Unlike feature

I am building post like / unlike feature using React context, but I have no idea what to do in reducer to update UI. Currently when I click like / unlike button, ui doesn't update instantly, have to refresh page to see the update. backend…
Farhan Farooq
  • 193
  • 2
  • 13
0
votes
1 answer

useReducer actions called twice and the state never updates inside the containing hook

I'm creating a custom hook to be reused all over the app but I got unexpected results as you can see through the comments in the code the actions are dispatched successfully and has the expected payload value and any code I pass to them runs…
Mostafa Hesham
  • 547
  • 4
  • 14