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

Reducer update another component of the list

I am self-training in React, and I have a problem that I can't find any solution, I hope you can help me. Here is my problem: I have a component that contains a list of products, this list is managed with a reducer (add, delete and modify). This…
dmi
  • 1
  • 1
0
votes
1 answer

Array is not iterable in useReducer()

To practice React hooks I wrote a simple todo site with ReactTS. I faced a problem that I keep receiving an error that my todos array is not iterable, despite it is defined as TodoProps[] in State type Error occurs logically after 'add' button…
Lvasche
  • 91
  • 1
  • 9
0
votes
0 answers

Why is react-router-dom navigate function executed before dispatch is done?

I have useAPIRequest custom hook as follows: import { useNavigate } from "react-router-dom"; import { routes } from "src/routes/routes"; import {useState} from "react"; import {useLocalStorage} from "src/hooks/useLocaleStorage"; import…
Boky
  • 11,554
  • 28
  • 93
  • 163
0
votes
0 answers

Console throws an error with useReducer on a calculator app

My first try on working with useReducer() on a calculator mini-project. But is throws an error whenever I try clicking on buttons: line 136 (const inside App function) in my code looks alright? function App() { const [{ currentOperand,…
keyc9
  • 15
  • 5
0
votes
0 answers

React useReducer setup for large state

I have a React application with a rather large state. I have been using useState since the beginning, but it has grown a lot and suddenly there are almost 100 useState lines. Now I think it is time to switch to useReducer (I know - I should have…
KMK
  • 1,439
  • 5
  • 21
  • 39
0
votes
0 answers

useReducer - changing the initial state object shape to match the backened requirement

Here is a reducer I created used in a custom hook for a form. const initialStateObject = (nestedKey) => ({ value: '', touched: false, hasError: false, error: '', nestedKey }) export const INITIAL_STATE = { name: initialStateObject(), …
HelloWorld
  • 10,529
  • 10
  • 31
  • 50
0
votes
0 answers

union of types with different generic parameters

I'm using reducers in React using useReducer. I have several actions whose correct types require different generic parameters. However, I have to export a single Action type to use with the dispatch method everywhere. Taking a union of two types…
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
0
votes
1 answer

Using union types in conditional blocks in typescript

I am learning typescript and trying to strong-typed useReducer with reactjs. This is logic for reducer, but typescript is yelling at me that property incStep doesn't exist on Act because it doesn't exists on Decrement. type Increment = { type:…
0
votes
1 answer

after adding two list delete cycle is not property working in react useReducer?

I am creating a shopping cart lit application, in that program add functionality is fine but when I add one list then another enter code here and then remove the one that is fine but when you want to delete two that is not able to deleted, also…
0
votes
0 answers

UseReducer initialization

function Init(){ var form={}; axios.get(`http://localhost:3001/exercises/${ex_id}`) .then(res => form={...res.data }) .catch(err => console.log(err)); console.log(form) return{form} } //console.log(form) const…
0
votes
0 answers

Firebase does not perform update on second request

I am having problem with updating document in firebase. I am a bit new, so this question is probably very silly but I wasn't able to find an answer online. I have a collection in my firebase called 'therapists', which contains some information. I…
0
votes
1 answer

dispatch is not a function at onClick in reactjs

I want to write context with UseReducer hook but an error error this:dispatch is not a function what is problem? please help me guys almost is correct but not working it. I want to see the appropriate action by clicking on the buttons, one is…
0
votes
0 answers

CRUD with React edit page with useContext, useEffect not working as expected

I recently started learning React, so I'm trying to make a CRUD but I am facing a problem with the useContext and useEffect, I am currently working on the edit page and I think I almost have it, the problem is that when I use the useEffect hook is…
0
votes
0 answers

How to guarantee that a reducer will have a certain set of action and parts of state

I have a set of reducers that I want to make sure that will always have certain 3 actions types (but allow for me to have more). Same for state. Have to have 3 pieces of state but allow for more Sample code: interface iFilterReducer { (state:…
GlutVonSmark
  • 284
  • 2
  • 9
0
votes
0 answers

How to update Form options after submitting using useReducer

i´m new at programming.. I'm coding a form that has a Select list of Options, which come from an array of objects (i named it initialState for useReducer use). Now i have to use the useReducer hook to update those options when the form is submitted.…