Questions tagged [reducers]

Refers to reducers in the mapreduce framework. Mappers split up a large problem and solve parts of it in parallel. Reducers collect and summarize the output of a map method.

Reference: https://en.wikipedia.org/wiki/MapReduce

819 questions
269
votes
7 answers

Can I dispatch an action in reducer?

is it possible to dispatch an action in a reducer itself? I have a progressbar and an audio element. The goal is to update the progressbar when the time gets updated in the audio element. But I don't know where to place the ontimeupdate…
klanm
  • 3,168
  • 3
  • 19
  • 22
87
votes
7 answers

When should I add Redux to a React app?

I'm currently learning React and I am trying to figure out how to use it with Redux for building a mobile app. I'm kind of confused on how the two are related/usable together. For example, I completed this tutorial in React…
user3802348
  • 2,502
  • 11
  • 36
  • 49
79
votes
7 answers

Why does TypeScript infer the 'never' type when reducing an Array with concat?

Code speaks better than language, so: ['a', 'b', 'c'].reduce((accumulator, value) => accumulator.concat(value), []); The code is very silly and returns a copied Array... TS complains on concat's argument: TS2345: Argument of type 'string' is not…
millsp
  • 1,259
  • 1
  • 10
  • 23
58
votes
7 answers

ReactJS: How to handle Image / File upload with Formik?

I am designing a profile page for my site using ReactJS. Now my question is how do I upload the image from local machine and save it to the database and also displaying it in the profile page import React, {Component} from 'react'; import { connect…
TMA
  • 1,419
  • 2
  • 22
  • 49
50
votes
2 answers

correct usage of reduce-reducers

I don't understand what reduce-reducers is meant for. Should it be used in the case that I have 2 reducer functions containing the same action? function reducerA(state, action){ switch(action.type): ... case 'SAME_ACTION':…
Amio.io
  • 20,677
  • 15
  • 82
  • 117
50
votes
9 answers

Redux store does not have a valid reducer

Haven't been able to find anything around here regarding this error: "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers." My reducer export default function…
chrysillo
  • 732
  • 2
  • 9
  • 17
42
votes
6 answers

React useReducer: How to combine multiple reducers?

I'm not a Javascript expert so I wondered if anyone has an "elegant" way to combine multiple reducers to create a global state(Like Redux). A function that does not affect performance when a state updating multiple components etc.. Let's say I have…
Freddy.
  • 1,593
  • 2
  • 20
  • 32
39
votes
3 answers

Accessing a part of reducer state from one reducer within another reducer

I do not know how to access a boolean isLoading flag from reducerForm.js reducer in reducerRegister.js. I have used combineReducers() and I use isLoading to disable a button during form submit. It's initial state is false, after clicking submit, it…
Ilija Bradaš
  • 645
  • 2
  • 9
  • 11
35
votes
5 answers

Accessing a reducer state from within another reducer

I have a reducer whereby I am retuning the appropriate state when an action is dispatched. Now I am calling an API at regular intervals so the result will trigger an action again and again. So what I want is that if the reducer state already has…
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400
22
votes
3 answers

Update single value in item array | react redux

I have a todo list and want to set the state of that item in the array to "complete" if the user clicks on "complete". Here is my action: export function completeTodo(id) { return { type: "COMPLETE_TASK", completed: true, …
Filth
  • 3,116
  • 14
  • 51
  • 79
21
votes
1 answer

Redux: Colocating Selectors with Reducers

In this Redux: Colocating Selectors with Reducers Egghead tutorial, Dan Abramov suggests using selectors that accept the full state tree, rather than slices of state, to encapsulate knowledge of the state away from components. He argues this makes…
pjivers
  • 1,769
  • 18
  • 27
17
votes
2 answers

“Combiner" Class in a mapreduce job

A Combiner runs after the Mapper and before the Reducer,it will receive as input all data emitted by the Mapper instances on a given node. then emits output to the Reducers. And also,If a reduce function is both commutative and associative, then it…
wayen wan
  • 207
  • 1
  • 2
  • 7
14
votes
3 answers

React Redux : Action creator not calling reducer

My action creator is not calling my reducer. Any help will be much appreciated. types.js export const SELECTED_FOOD = 'selected_food'; index.js (action creator / action) import { SELECTED_FOOD } from './types'; export function…
kennedy
  • 151
  • 1
  • 3
  • 6
13
votes
1 answer

How do you clean up Redux' state?

As a Redux beginner, given (the idea of) a somewhat larger application I imagine a root reducer similar to: const rootReducer = combineReducers({ accounting, crm, sales }) Application state in this case would contain accounting, crm, and sales even…
Thomas Luzat
  • 710
  • 7
  • 21
12
votes
2 answers

React Redux error: default parameters should be last default-param-last

Using Redux in React I'm having a warning that the default parameters should be last default-param-last. on the line where I created the const warehouse. is there wrong on how I created the code? or is there a better code for that? Here's my…
Rcandy
  • 123
  • 1
  • 1
  • 6
1
2 3
54 55