
So I'm just kind of taking this pattern from their documentation.

Okay, export const (adopt) equals adoptedPetSlice.actions and export default adoptedPetSlice.reducer. It's okay, I promise it's okay to do it this way. Does that make sense? This is kind of a weird API, I mean, it's very succinct, right? But if you come from a functional programming background, it feels really weird to operate on your parameters. This is your opportunity to change the state. We're just saying that this is the new state, right? But I mean, I don't know let's say it was important that the name be to uppercase, right? You could do all that stuff here. So whenever someone adopts something, we're just saying, this is now the adoptedPet, right? So in this case, I'm gonna say state.value is assigned action.payload. It performs some action to it and returns new state.

And all it does is it takes an old state. So what is a reducer? A reducer is just a fancy term for, it's a function that takes an old state and something that you wanna change about the old state. You can give it a bunch of reducers, I'm gonna give it just one reducer. And then we're gonna give it a bunch of reducers. So we're going to give it a value of null, I don't want it to be set to anything right because no pet has been adopted until they click the AdoptPet button. The initial state, we have to give us some sort of initial state of like what we want this particular item in our little database to be when you first create it. What is the name of the slice this name is the adoptedPet, okay. And then we're going to export const adoptedPetSlice = createSlice, so first of all you have to give it a name.

So import, create slice from at Redux toolkit. That the term that they use to describe that bundle of putting everything together is a slice. What is a slice? A slice is kind of a new idea for Redux Toolkit, but basically it's the idea of, I'm putting all the reducers, and action creators and all that stuff together in one particular bundle, right? So you can just delete that from your app and make a file called adoptedPetSlice.js. Let's go ahead and delete adopted pet context coz we're not gonna use that anymore. Now we have access to reducts inside of our applications. Transcript from the "Creating a Slice" Lesson
