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
2 answers

How to migrate Redux to React hooks

I am currently trying to migrate Redux files to React hooks (useReducer) with minimal changes. I am reusing Redux reducers and the initial states. e.g. export const INITIAL_STATE = { locale: "en" }; export const reducer = (state =…
nomadus
  • 859
  • 1
  • 12
  • 28
0
votes
1 answer

how to remove comments in nested arrays using useReducer?

i use useReducer + useContext to change global state, please tell me how to remove comments using useReducer interfaces interface image data array export const listsData:IData[] = [ { id: 'list-1', listTitle: 'TODO', cards: [ { …
0
votes
1 answer

React - state does not update with useReducer

I want to get the heights of the rendered list items into an array stored in a parent component. It looks fairly simple but still it does not work. From what I see when debugging, the dispatch is fired and the reducer receives the action, but yet…
bakrall
  • 465
  • 7
  • 21
0
votes
1 answer

React useReducer sets the whole state as undefined

I'm having a problem where updating my Context state with a reducer, sets the whole state as undefined... This is my code: const [state, dispatch] = useReducer(AccountReducer, initialState); The call to the Dispatch dispatch({ type: SET_TOKEN, …
Hely Saul Oberto
  • 577
  • 1
  • 10
  • 22
0
votes
1 answer

How to define combinations in typescript? Solution: discriminated-union

I am using Typescript, I am wondering if it is possible to define what combination can be put into the function. I have following code (very simplified): interface actionType { type: string, payload: { count?: number, first?:…
0
votes
1 answer

Parsing items from Local Storage Error using Context and useReducer

I am having issues pulling data from local storage in my next.js e-commerce app. Originally I am saving items to cart from within my cart-context file and with useReducer. In the cart provider component I am involving useEffect and setting the…
Felipe
  • 333
  • 7
  • 19
0
votes
1 answer

Check if item already exists in cart when adding REACT

I have a cart. When adding a product it is having trouble for it to properly check if the same shoe and size already exists then to add it towards the quantity. For example Starting with an empty cart, I add a shoe to cart of size 8 with a quantity…
pNut
  • 21
  • 5
0
votes
1 answer

initialState resets after dispatch actions in react useReducer

In my app, I fetch users data from the server inside the useEffect hook and set the initialState of the useReducer. When action dispatch happens on text input change, the initialState resets instead of updating thus I can't type a word inside the…
0
votes
1 answer

confused by UseReducer

Hey everybody I wonder if someone would be able to help me understand useReducer. It was suggested to me by someone because I am using a form with lots of inputs which I would like to dynamically other areas of the app. I'm new to react and i'm…
Mark Scholes
  • 75
  • 2
  • 6
0
votes
0 answers

why is my gloval setInterval ID variable unavailable to a function?

I am writing a simple timer app and using setInterval for the first time. The project is in react typescript and I use the useReducer hook to manage state. The project requires two separate timers, session and break, which may explain some of the…
Mac Bubb
  • 59
  • 1
  • 8
0
votes
1 answer

How to design state based on useReducer

I have the below requirement: We have a fleet of 10 trucks. Each truck can carry different loads, for our use case the load is medications. A Truck has: serial number (100 characters max); model (Lightweight, Middleweight, Cruiserweight,…
0
votes
1 answer

useReducer and userContext Typescript not working as intended

this is my first using useReducer and useContext with Typescript and I'm creating a simple counter. I'm trying to update the count using increment and decrement dispatch but it doesn't change and no error in terminal. Here is the link to…
MikMik
  • 3
  • 4
0
votes
1 answer

filter a list with useReducer hook in React?

I need to know how I can filter an object with the useReducer function in the form of a list. I want it to work based on the object's progress. I'm new, do I need to map something too? const data = { title: "Title", lessons: [ { title:…
lache
  • 608
  • 2
  • 12
  • 29
0
votes
1 answer

Can't share state between tabs in react app

I am building the amazon clone from the clever programmer youtube channel and when I open a second tab, the basket is not shared on that tab, but if I login, the signin change to signOut in both tabs, so it's confusing. for the state management, I…
0
votes
3 answers

React TS useContext and UseReducer with axios

I am making an Axios call to get data. What should be the type for Axios call? For now, the type is any but how can I make it more strict? import axios from "axios"; import { createContext, useEffect, useContext, useReducer } from "react"; import {…