Questions tagged [redux-reducers]

195 questions
2
votes
0 answers

Redux Toolkit Reducers and ExtraReducers : Calling a reducer that has a prepare callback from within an extra reducer doesn't call reducer

I am building a notification system using Redux Toolkit and I am running into an issue. Here I want to trigger the showNotification when certain actions/reducers in other slices are called. So I have added extraReducer to my NotificationSlice. When…
2
votes
1 answer

How to call other reducers in createSlice to change state?

I use redux to createSlice, here is my createSlice looks like: export default createSlice({ name:'testSlice', initialState, reducers:{ setRecords: setRecordsReducer, setObjects: setObjectsReducer, setBoth:.... …
spspli
  • 3,128
  • 11
  • 48
  • 75
2
votes
1 answer

If i have 100 reducers in my react app will all reducers get called when an action is dispatched?

If so will this lead to a performance issue ? Secondly Is there a way to specifically call a reducer without invoking all 100 reducers ?
2
votes
2 answers

JavaScript strange behavour on object assignment

I am currently writing a Redux reducer and I am facing an issue with the state update. The code bellow is supposed to toggle an open state. The problem is that the resulting state does not return the same value depending on how one accesses it. case…
Robert
  • 21
  • 2
2
votes
1 answer

Using {...state} instead of state in persistReducer in redux

So I was using redux-persist in my react-native app to persist the state and everything is working fine. For the reducer, I was using switch-case to check for different action-types, and for the default, I was returning the state. initialState = { …
Irfan wani
  • 4,084
  • 2
  • 19
  • 34
2
votes
2 answers

How to pass in the state to the dispatch action if using useState instead of this.state in react?

I am a beginner starting out in react and having difficulties in state management while working with react-redux and useState. In the below code I am basically following a tutorial which passes in the this.state to the dispatch action createProject…
nikkbh
  • 77
  • 5
2
votes
1 answer

React createSlice's extraReducers's state access

i have the following code: import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; import { client } from '../../api/client'; const initialState = { logBook: [], status: 'idle', error: null }; export const logNewEntry =…
Han
  • 63
  • 11
2
votes
2 answers

How to implement an exhaustive switch statement inside a Redux reducer function using Typescript? How to handle Redux's internal @@redux actions

I've tried to find a definitive answer do this, but haven't found one yet. There a question here on SO that answers how to implement an exhaustive switch statement: How do I check that a switch block is exhaustive in TypeScript? And the answer…
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
2
votes
1 answer

React. get state from another reducer

Hi how can i get the value from another reducer? const indexReducer = (state = initialState, action) => { switch (action.type) { case CALC_BET_AMOUNT: function calcBetAmount(value) { switch (value) { case…
2
votes
0 answers

React reducers, state not updating immediately

i am working on createContext and reducers, with reducers i am updating state value, but it is not updating value at a time, i did console.log(user); in onSubmitSave(), but in console log i am not getting its updated state at a time, i can see it…
Nikul Panchal
  • 1,542
  • 3
  • 35
  • 58
2
votes
2 answers

(import from default export) Is the root reducer in Redux automatically called 'rootReducer'?

I'm going through many Redux-tutorials, and something that confuses me, is the fact, that when creating a Redux store with a combined reducer, there often is the reference to a name rootReducer as the root reducer, although it has never been…
Schelmuffsky
  • 320
  • 1
  • 13
2
votes
1 answer

Better way for writing the reducers?

Is there a better way for writing the following code: export const getItemsSuccess = (state, entity, payload) => { const {count, rows} = payload const clonedState = {...state} clonedState[entity] = {...clonedState[entity], count, rows} …
Yaniv Or
  • 57
  • 1
  • 6
1
vote
1 answer

Why is Store.getState() returning 'any' type after using rootReducer with combinedReducers?

I am trying to use a root reducer to wrap my combined reducers in order to reset them on reset store action. However, after using root reducer I am unable to directly access reducers by Store.getState().recuder1 Typescript does not give me any…
1
vote
2 answers

How to update one specific item in react redux?

Initial state of react redux. reducer.js cart { id: 100, name: "Pizza", price: 550, category: "Fasting", time: "20-50 min", restaurantId: "BH001", quantity: 1, photo: { fileName: "", fileType: "", filePath: "", }, …
1
vote
2 answers

Uncaught Error: "reducer" is a required argument, and must be a function or an object of functions that can be passed to

I have done hours of debugging and I am unable to find the solution. import { combineReducers, applyMiddleware } from 'redux'; import thunk from 'redux-thunk'; import { configureStore } from '@redux.js/toolkit'; import { composeWithDevTools } from…
1
2
3
12 13