Questions tagged [redux-reducers]

195 questions
0
votes
1 answer

Should all redux actions have a corresponding reducer?

I think Redux is pretty useful for debugging because it tracking what actions were dispatched by your app in its dev tools. Is it bad practice to dispatch an action with no intention of handling it with a reducer? For example, I want to make an…
alanrzhang
  • 199
  • 1
  • 1
  • 7
0
votes
1 answer

Why state variable inside redux Reducer not not increment by 1

I have a simple two button on the web page one for increment and one for decrements an integer. Once i click on + button it will add 1 to the current value. Below is my Reducer and i have wrapped "INCREMENT" with a setTimeout and when i click on +…
Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92
0
votes
3 answers

In a Redux reducer, if state is not defined, can you immediately return the initial state?

I have seen 3 forms of reducers: // Form 1 function reducer(state, action) { if (state === undefined) return state = []; // handle action.type // ... } // Form 2 function reducer(state, action) { if (state === undefined) state =…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
0
votes
1 answer

What exactly does it mean when we say we cannot mutate the state object in Redux reducer?

Does it exactly mean treating it as "read-only"? For example, if the state is: { arr: arrData, obj: objData, aMap: mapData, aSet: setData } For any of the four that has no change to it, we can keep it as is, but let's say 3 level down obj,…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
0
votes
0 answers

Redux React state not getting set after data received from reducer

i do have a component in which state={ mediaJson=[] } and i have a reducer which calls an API and returns data and i used static getDerivedStateFromProps(props, state) { return{ mediaJson:props.data } i am getting the data and ist getting…
midhun k
  • 546
  • 1
  • 12
  • 28
0
votes
2 answers

React Redux -possible to have a call back in dispatch function

Guys i am having some trouble or quite doubtful. am having one component and one reducer. Reducer.js import { ASSET_POPUP_GET_ENDPOINT, } from 'apiCollection'; import { performGet } from 'services/rest-service/rest-service'; export const…
midhun k
  • 546
  • 1
  • 12
  • 28
0
votes
1 answer

Problem with Reducer that contains few different values

I'm kind of new to React.js & Redux, so I have encountered a problem with Reducers. I am creating a site that have a main "Articles" page, "Question & Answers" page, I created for each one a separate Reducer that both work just fine. The problem is…
0
votes
1 answer

Type { error } is missing in Type , but is required in type - Redux Specific Problem

I have a small problem, typing my Redux Reducer. I know this question, has been generally answered, but I find the solutions lacking, and I would call them more workarounds than anything else. The Problem: I have a Redux Reducer. Inside it, 3…
user10104341
0
votes
0 answers

PreloadedState not reflecting correctly after multiple combineReducers

The state of my application is as follows: body: { data: [], style: {}}}, block:{} I have 2 separate reducers for data and style and no reducer for body. Am combining reducers in the following way: const body = combineReducers({data,…
jsdev
  • 101
  • 7
0
votes
1 answer

Reducer returned undefined during initialization

I am stuck on this from a long time, and none of the online support till now helped much. I am trying to use immer for immutability in my React-Native app. But the reducer part gives an error saying reducer "count" returned undefined during…
0
votes
2 answers

Can't update a nested object's property using Redux

In React we have a best practice not modify state directly i.e. mutation... It is also important in Redux... /* initial state */ export const usersStartState = { users: { isLoggedIn: false } } export default function users(state = usersStartState,…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
-1
votes
1 answer

How can I make this redux function more efficient?

My initial version did not use cloning. However useSelector() was not firing until I added another clone statement. I thought that by cloning the containing object on a state change this would cause it tor fire. Particularly this line here. let…
-1
votes
1 answer

react redux dispatch to reducer in createslice not work

I friends, I develop react redux toolkit slice everything ok but in function dispatch not working send to dispatchUserBlockingUpdate function in react-dom.development.js where is the my problem ? I look changeProfitSortType function get data when…
-1
votes
2 answers

Merge array object elements with same key in Redux reducer

My reducer is as follows: export const favorites = (state = { favorites: [], countFavorite: [], }, action) => { switch (action.type) { case ActionTypes.ADD_FAVORITE: return { ...state, favorites:…
Cho Cho
  • 159
  • 3
  • 12
-2
votes
1 answer

How to create custom middleware in reactjs to update reducer?

I want to update reducer when api sends response with updated token. I have tried dispatching action from middleware but reducer is resetting to its initial state.
1 2 3
12
13