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

add property to object in state array with useReducer

I have an array of objects stored in state that looks like: { "file": {}, "myFsize": 1321, "fileType": "image/jpeg" }, { "file": {}, "myFsize": 999, "fileType": "image/jpeg" } ] I am using…
Nick Wild
  • 525
  • 1
  • 11
  • 22
0
votes
1 answer

React Use Reducer Firing twice

My issue is when Im' trying to toggle boolean value within my useReducer function, by doing this it is causing the issue of the value changing back to the original: function reducerBalls(state: any, action: any) { let newState; let item; …
Sukh_Bains
  • 116
  • 7
0
votes
1 answer

paste token using useReducer with useContext and get undefined part 2

yeah i know this is my part 2 problem. You can see the part 1 in paste token in useReducer with useContext in nextjs and get undefined. So in the part 1 my problem was solved and i didn't get undefined anymore but instead i get an empty object on…
0
votes
1 answer

Can we use customHooks into redux Saga function

Following custom hooks as state selector and using that within "functional View" component. Now, I need to use that in redux Saga function. Can we use that into Saga function or I have to use some other approach instead of using custom hooks into…
dsi
  • 3,199
  • 12
  • 59
  • 102
0
votes
1 answer

useReducer and state managing

hey guys im learning the useReducer hook and for the most part it seems to be quite similar to redux (minus the action being sent to the store etc) the thing i seem to ALWAYS have problems with when i get more complex state management situations is…
Robert O'Toole
  • 197
  • 1
  • 11
0
votes
2 answers

Trying to use react-admin transform function on

I'm new to react-admin and I am trying to build a custom image gallery input. it should show a modal with images (data is already fetched and stored in the redux) so the user can select one or more images (upon selection an action is dispatched to…
0
votes
1 answer

dispatch usereducer in gatsby

I am new to gatsby and hope you can all helt me. I am getting a typeerror: dispatch is not a function message, and have stuggled with finding my typo for two days now. I am trying to make a cart and need to pass the product to a global state. It is…
0
votes
0 answers

Using Dispatch Function to Conditionally Render Components

So I've just refactored an app created in react using useContext/useReducer in order to manage the state better. I'm having a great time and have managed to get the dispatch function to work with bits you have to select. HOWEVER. When it comes to…
0
votes
0 answers

The state of multiple components store in an array is not changing

I have a single component that will be injected into the DOM on every onClick event. I intend to manage both the future and previous state of the component irrespective of its number injected into the page. Also, I intend to make each instance of…
idysman
  • 9
  • 2
0
votes
1 answer

usereducer - only persisting certain state to session storage?

I have a quiz on verb conjugations. You send filter options on the conjugations you want to the backend, and it sends back the necessary information. In my quiz page, I have a usereducer which will manage all this state. I want the conjugation data…
jake_prentice
  • 71
  • 2
  • 9
0
votes
2 answers

How do I convert a promise into the array it holds?

I am using React useReducer and trying to display the information taken from firebase. async function reducer(listState, action) { switch (action.type) { case "load": let stateCopy2 = [...listState]; let…
Alexander Hemming
  • 753
  • 1
  • 6
  • 28
0
votes
0 answers

How do I add Elements to an array in useReducer that is generic type in react

Am looking into old code & I have a generic reducer that handles fetching off data and the initial state looks like this const initialState: State = { status: STATUS.INIT, data: undefined, error: undefined, } Since I don't know…
user3476614
  • 537
  • 2
  • 8
  • 26
0
votes
3 answers

simple useReducer for learning

I'm learning the useReducer from official web and my code doesn't work ok, Im not sure how initialCount should work. Any help would be greatly appreciated! import React, { useReducer } from "react"; const reducer = (state, action) => { switch…
Norby
  • 321
  • 1
  • 4
  • 13
0
votes
1 answer

TypeScript & React: reusable generic actions / components

I use TypeScript with React and useReducer and I want to define reducer Actions in a type-safe way. The simplest approximation of Action is: type Action = {name : string, payload : any} The more precise version requires union types: type Action = …
Ivan Kleshnin
  • 1,667
  • 2
  • 21
  • 24
0
votes
1 answer

Wanting to add a second React reducer with useReducer

I currently have a single reducer that first checks for if SUCCESS or FAILURE is sent as an action. Only once the loading state is false, do I want the other actions to be checked. I realize the code below is not quite right, but just wanted to…
Peter Kellner
  • 14,748
  • 25
  • 102
  • 188