From the course: Learning NgRx

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reducers in NgRx

Reducers in NgRx - Angular Tutorial

From the course: Learning NgRx

Start my 1-month free trial

Reducers in NgRx

- [Instructor] So now our actions are basically ready at this point. They're ready to go, and the only step missing for us is to actually use them. So what we're going to do is move to our reducer function, and in our reducer function, we want to be able to handle these two different actions. So first we're gonna add a case for the AddZipcode action. So that's what I do here. I'm importing the zip code action types from our actions file up there, so my IDE did that for me automatically, and now I can just handle that case here. And what I'm going to do is return a new state. So we want to change a state, and first we create a copy of the old state, so what this statement does at this point is it takes the old state, creates a new object with the old state copied into it. And then in here, we want to add our new zip code. So our state has a zip codes property where we want to first copy all of the other zip codes, if any. So using the same array spread syntax with the three dots, now…

Contents