Mir
Mir

Reputation: 75

From where does reducer get the current state

I was redux and came across the term reducer and then I found this article https://daveceddia.com/what-is-a-reducer/ explaining how reducer works. But what confused is this statement in that article:

(state, action) => newState

As in: it takes the current state, and an action, and returns the newState.

The question is from where does reducer receives the current state?

Upvotes: 0

Views: 247

Answers (2)

Alan Paul Mathew
Alan Paul Mathew

Reputation: 219

The reducer accepts the current state/previous state and an action. According to the action type, it will return new state.

ie; (state, action) => newState;

Upvotes: 0

Dennis Vash
Dennis Vash

Reputation: 53874

From redux docs:

type Reducer<S, A> = (state: S, action: A) => S

Reducers calculate a new state given the previous state and an action.

Reducers "receives" the state from the previous state.

For what "the previous state" means you can read the related sections state and store.

Upvotes: 2

Related Questions