Check out a free preview of the full Redux Fundamentals (feat. React) course

The "Create a Slice Solution" Lesson is part of the full, Redux Fundamentals (feat. React) course featured in this preview video. Here's what you'd learn in this lesson:

Steve live codes the solution to the Create a Slice exercise.

Preview
Close

Transcript from the "Create a Slice Solution" Lesson

[00:00:00]
>> All right, so in the very beginning our human size, it'll take some differences. It'll be a little bit different a little bit cuz we have this relation between the tasks and the human but the very sensitive we're just adding the human. It's not that much just similar but let's take a look, so we've got this idea of we'll have a create human helper as well, this one will take a name.

[00:00:26]
If you looked at the component you see it's not expecting a tile it's expecting a name in this case. And we will return the ID which is again gonna be this Nano ID and we'll call that a function and the name, and then we'll take task IDs. We'll keep an array of all the IDs, and this is mostly demonstrate one of the things we've questioned before.

[00:00:50]
Which is like, do actions really go through all the reducers and we'll make some initial state, we will make an array. I'll be one, make one for Mark Welcome Tanner. Cool, so we've got all of that in place and now we're just gonna create our slice, And let's make sure we import that, with the auto complete there.

[00:01:41]
Sweet, and this one is gonna be the name humans. We'll pass in that initial state and the reducer is gonna be somewhat similar to what we had before except we're gonna use a name instead. We'll add and we'll say a state and action and we will immediately do the state dot push.

[00:02:12]
Create human with that action payload. And one of the reasons why we stuck with the flux standard actions in the very beginning. Is because again, Redux token is just going to assume that best practice as well. We're gonna see that the action creators are just going to put stuff in a payload on our behalf, whether we're ready for it or not.

[00:02:33]
So let's actually get that into our store. I don't know why it wants to capitalize that we'll fix that human dot reducer. And so now we should actually have the state in place and we're gonna see something kinda interesting in a second. But if we look, I'll give it a quick refresh and we've got our humans in there, they're all everything is kind of as we would expect it to be

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now