Questions tagged [redux-reducers]

96 questions
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
  • 528
  • 2
  • 11
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 => { …
kinza
  • 225
  • 2
  • 9
3
votes
1 answer

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
  • 5
3
votes
0 answers

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,071
  • 2
  • 17
  • 37
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
  • 5,264
  • 21
  • 64
  • 138
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 =…
Hang Lin
  • 57
  • 6
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…
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…
taks
  • 868
  • 9
  • 31
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
  • 6
1
vote
2 answers

why my reducer is slow to storage the result?

EDIT: i have adjusted my code a bit, and now i am pretty sure that my reducer returns undefined at the 'action' no matter what comes in. So I think it is the thunk that is the problem, or the combinereducer. Additionally i have return fixed…
Om Alba
  • 11
  • 3
1
vote
1 answer

React redux - pushed object in the state is not mapped but initialState is

I am working on some app where you can save a note about a video. I have some redux issues, sorry that I am not specific but I don't know where the problem is. Every time when I am using 'ADD_ITEM' action, everything works fine in the devtools I can…
1
vote
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
  • 35
  • 4
1
vote
1 answer

(React Redux) The whole state restarts and deletes all changes made when I add a new item

The reducer goes like this: import { CREATE_COUNTRY, } from "../actions/actionConsts" export const storeInitialState = { countries: [], otherThings: 0 } export default function countriesReducer(prevState = storeInitialState, action)…
Rafael
  • 1,333
  • 3
  • 18
  • 37
1
vote
1 answer

How do I fix my reducer to return the property value of an object?

I have a reducer in my react native app which ideally should check the state and return if the recipe has been favourited or not. I've tried to create a reducer to return if isFav is true or false for a recipe object in the state. If the recipe is…
Ashley Vaz
  • 55
  • 6
1
2 3 4 5 6 7