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

Changing JSON data source at certain viewport in react

I am working on a project using react where I plug in data from a JSON file into a reducer function to manage the content state. However, at a certain viewport, another image is provided that needs to be displayed instead of the other image. If I am…
Kade
  • 5
  • 3
0
votes
0 answers

Redux, side effects and updating store In Next.JS with TypeScript

Repo for reference: https://github.com/G-bot987/NextDnDCharacterManager I should start by explaining I'm completely new to redux, so the code I've written may fly in the face of best practice, in which case I'd like to know! been stuck on this issue…
G-bot987
  • 1
  • 1
0
votes
0 answers

Scientific Calculator with TypeScript & React crashes when I try to do more than one calculation

The GitHub repo has all the code: https://github.com/isZachariah/scientific-calculator Don't judge the styles its not anywhere near done, just the basics so far. I built a custom hook that uses useReducer and when you press the '=' button it calls…
0
votes
0 answers

should i store logged in user data in authReducer/authState ? REACT

i already have an auth reducer. this is what its look like now : REDUCER INITIAL STATE --- { loggedIn: false, token: '' } should i do this instead ?? : { loggedIn: false, token: '', address: {}, phoneNumber: '', emailAddress: '', …
0
votes
0 answers

dispatch inside loop, loop finishes before dispatch execution

I'm doing an app in React to help in the creation of a team for a game, a team has 7 members and each member has some characteristics than can increase the ATK or DEF of said member if said characteristic is shared with other team member. So, if two…
0
votes
1 answer

useReducer - Counter does not work on production

I made an online store, but the counter for adding products to the cart does not work on production (everything works on localhost). ProductHero.tsx (component code where the counter is): import { useAppDispatch } from 'hooks/useRedux'; import { FC,…
Michał
  • 3
  • 1
0
votes
0 answers

How to use a discriminating union type for an initial value in a useReducer?

Is there a way to properly type an initial value in a useReducer hook using a discriminating union? I am passing an initial value into my context that can either be an object of Dog or Turtle. I am getting an No overload matches this call error…
Jennifer
  • 101
  • 1
  • 4
0
votes
0 answers

Can affect performance using many Context Provider in React?

Option 1: Each Provider component contain its own useReducers /*...*/ /*...*/ or Option 2:…
0
votes
0 answers

React Native - Why doesn't my app change screens after state is updated?

In my App.js I call a function that checks the local storage to see if the user is logged in: function App() { const {state, tryLocalStorage} = useContext(AuthContext); useEffect(() => { tryLocalStorage(); }, []); return ( …
jdez
  • 189
  • 1
  • 10
0
votes
1 answer

React useReducer hook does not let me change input values of user information form

First time asking. Thanks in advance, hope I explain my problem properly. A few weeks ago I started working with MERN stack and my problem appeared while trying to build a form where users could see/update their personal info. To achieve this, I…
0
votes
1 answer

PATCH request seems like a step behind

Hey folks really hope someone can help me here. I'm successfully updating my object in my mongo cluster, it updates but it does not render that update straight away to the browser. It will only update after a reload or when I run my update function…
fluffy-lionz
  • 81
  • 2
  • 12
0
votes
1 answer

Update my state after PATCH request - useReducer, context

I'm successfully updating my plant object to my cluster, but it takes a page reload in order for me to get that updated data. I'm assuming that I may need a useEffect to call my fetch again but I'm unsure how I would do that after my PATCH…
fluffy-lionz
  • 81
  • 2
  • 12
0
votes
1 answer

React useEffect and context stuck in an infinite loop - "maximum update depth exceeded" console error

I'm using React Context and a reducer for state management, and I would like my app to check whether a given state is empty when the user logs in - if yes, then it should fill the state with a value, and if no (so if the value has already a string…
0
votes
2 answers

Error on using spread operator with nested object and useReducer hook

I have following nested object as state. interface name { firstName: string; lastName: string; } type NameType = name; interface employer { name: string; state: string; } type EmployerType = employer; interface person { name: NameType; …
0
votes
0 answers

How to update child component is a state of useReducer when parent rerender

Situation: I have a parent component called TestReducerScreen Inside parent render, I change the body by use useReducer. State of reducer is a child component instead of variable. Child component I want it's a function render html inside parent…