Questions tagged [redux-reducers]

195 questions
6
votes
1 answer

Pros & cons of using extra reducers vs dispatching within async thunk

I'm rather new to the whole React & Redux ecosystem & am trying to understand when & why to use extra reducers vs directly dispatching actions within an async thunk when working with the Redux toolkit. Probably best explained with an example showing…
suamikim
  • 5,350
  • 9
  • 40
  • 75
5
votes
4 answers

Redux toolkit: Uncaught TypeError: Cannot read properties of undefined (reading 'type')

I get the following error when I add a specific action in the extraReducers inside a slice: Uncaught TypeError: Cannot read properties of undefined (reading 'type'). Example: import { createSlice } from '@reduxjs/toolkit' export const mySlice =…
L. Pier Roberto
  • 513
  • 1
  • 6
  • 20
5
votes
1 answer

Reducer In React Native Not Working (Not A Function)

Currently, I'm working on react native and using Redux I'm facing a problem, when dispatching the reducer, it saying not a function. here's how I configure the store import { configureStore } from "@reduxjs/toolkit"; import navReducer from…
Brown_MV
  • 69
  • 5
4
votes
3 answers

Bad idea to put a dom operation inside a redux reducer?

I have several actions which use the same reducer, and instead of having a dom operation in each of those actions, I want to just add it once inside my shared reducer. I know reducers are to be pure (which the returned data still is), but is this…
ram
  • 680
  • 5
  • 15
3
votes
1 answer

How to apply createEntityAdapter to createApi slice

I have implemented successfully a redux-toolkit api. Now Im trying to use createEntityAdapter to be able to use the pre-built selector methods. import { createEntityAdapter, createSelector, } from '@reduxjs/toolkit' import api from…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
3
votes
0 answers

Should I just use one reducer in redux for reactjs?

I think if we have multiple reducer, it is just namespacing the state, right? So if we don't need namespacing them, we could just use one reducer to store all the global state?
Aron
  • 169
  • 8
3
votes
1 answer

How to pass the parameters to a function converted from custom hook?

I have a custom hook, it will fire two actions in my Redux slice "myTestSlice", action1 and action2, behind each action, I have reducer function to get new state. const useSetMyObjects = ( actions, { object1Name, object1Id, object2Name,…
spspli
  • 3,128
  • 11
  • 48
  • 75
3
votes
1 answer

Redux: Call thunk action from slice reducer action

I have a tree structure which is loading children on demand, this is my reducer. The problem I have is that when I want to call my thunk action from toggleExpandedProp I get exception (see bellow). What should I do? import { createSlice,…
Teamol
  • 733
  • 1
  • 14
  • 42
3
votes
1 answer

React redux useSelector and parameters

I'm trying to understand why I can't seem to pass a parameter into a selector. In essence: I have a logic that stores a number and a bool - the number is the parameter I want to select a material element by - I have a button that dispatches an…
altruios
  • 986
  • 1
  • 10
  • 29
3
votes
2 answers

How can I delete Multiple array items

I'm using React js. I want to add an option to delete multiple items. but after deleting each item, page refreshes the props and not delete remaining items. How can I delete Multiple items? const onDeleteAll = arr => { …
the_developer
  • 747
  • 2
  • 7
  • 17
3
votes
2 answers

How can I sort an array using immer?

I'm trying to add an object to an array in a reducer, and after that, I would like to sort it by date (I can try to insert in order, but I think is more or less the same effort). I'm using immer to handle the reducer immutability: const newState =…
teo
  • 73
  • 7
3
votes
1 answer

How to set initial state for redux reducer in typescript?

I am getting this TypeScript error Property 'hasError' does not exist on type '(state: ErrorType | undefined, action: ErrorActionType) => ErrorType'. which I think its complaining about setting the initialState for reducer. import { ErrorType,…
Negin Basiri
  • 1,305
  • 2
  • 26
  • 47
3
votes
1 answer

Must a reducer in Redux strictly return a new state object?

One rule of reducer in Redux is: we should treat state as read-only, and return a new object as the new state. But there is one grey area: must it strictly return a new object as state, or can we return the same state object? It seems by looking at…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
3
votes
3 answers

Grouping array data according to a id

With a API call i'm receiving a response like below [ { stationId: "10" name: "Jinbaolai" group: {id: "18", stationGroupName: "Ali"} }, { stationId: "13" name: "Stack" group: {id: "18", stationGroupName: "Ali"} }, …
CraZyDroiD
  • 6,622
  • 30
  • 95
  • 182
3
votes
1 answer

How to share state between 2 combine reducers?

I have 2 reducers that I use and combine them. In the first reducer, I have something that gets all the initial data (which is also relevant for the second reducer). How do I use the data in the state that I initialize/set from the first reducer to…
David
  • 1,284
  • 1
  • 11
  • 21
1
2 3
12 13