Redux Toolkit Tutorial - 19 - Cake Slice

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น •

  • @vigneshgvs
    @vigneshgvs ปีที่แล้ว +6

    under the hood
    createSlice - under the hood uses the immer library. - to directly mutate the state.
    {
    state.numOfCakes-- //this is mutation, no care on rest of other props
    }
    new way: (file name should be of suffix: 'Slice')
    - also group together the reducer logic & actions for a single feature in a single file.
    - The entire application state is split into slices & managed individually.
    const createSlice = require('@reduxjs/toolkit').createSlice
    const initialState = {
    numOfCakes: 10
    }
    const cakeSlice = createSlice ({
    name: 'cake',
    initialState, //if both key & value are same, its better to write just once, //initialState: initialState,
    reducers: { // we specify the individual state transitions. value is object
    //eg: we have 2 keys 'ordered' & 'restocked'
    ordered: (state, action) => { //value is an arrow function
    //but for our example 1 parameter is enough, as just decreasing by 1.
    //1. we dont have to explicitly return new state
    //2. we can directly mutate the new state (wait what!!!! yes - createSlice - under the hood uses the immer library.
    state.numOfCakes-- //this is mutation, no care on rest of other props
    },
    restocked: (state, action) => {
    state.numOfCakes += action.payload
    },
    },
    })
    // what about the actions?
    //3. createSlice - will automatically generate action creators with same name as reducer functions
    //4. it also returns the main reducer function we can provide to our redux store
    //5. and returns actions as named exports
    module.exports = cakeSlice.reducer
    module.exports.cakeActions = cakeSlice.actions
    - this slice will take care of action constants, action object, action creator, switch statements in reducer, and handling immutable updates in the reducer.
    - this slice will generate cake reducers and cake actions.

    • @mostafashahat9760
      @mostafashahat9760 9 หลายเดือนก่อน +1

      Thanks a lot ❤

    • @Me-nh3pt
      @Me-nh3pt 6 หลายเดือนก่อน

      😀

  • @cdialpha
    @cdialpha 2 ปีที่แล้ว +8

    How does RTK / createSlice know what the action.payload should be?

    • @samialvi4226
      @samialvi4226 ปีที่แล้ว +2

      In the context of Redux, the "payload" is a term used to refer to the data that you include when you dispatch an action.

  • @mohamedsamy2315
    @mohamedsamy2315 2 ปีที่แล้ว +3

    we want tutorial ro rtk query (especially how to deal with manual refresh token ) and make production website with it

  • @ankurgupta4696
    @ankurgupta4696 2 ปีที่แล้ว +2

    why we used module.exports.cakeActions here??

    • @paraschawla3757
      @paraschawla3757 2 ปีที่แล้ว +2

      This will be used while dispatching actions from Store.js
      Wait for next video and you'll get to know

  • @IamPetrus
    @IamPetrus ปีที่แล้ว

    thank yoU Master!

  • @AbdulRauf-jy5oc
    @AbdulRauf-jy5oc 2 ปีที่แล้ว

    What about the default parameter of cake restock ?? In slice

  • @Amir-tt8qw
    @Amir-tt8qw ปีที่แล้ว

    I was thinking about the cake slice until he described it😂.

  • @codingpotato813
    @codingpotato813 2 ปีที่แล้ว +5

    Idk if someone get that cakeSlice pun or not. And at this point I'm too afraid to ask :)

  • @yasserhamody3388
    @yasserhamody3388 2 ปีที่แล้ว

    I try with the same code in the video and get this error message
    Error: Cannot find module './app' ..
    is there any solution ?

    • @rishabhmahajan409
      @rishabhmahajan409 2 ปีที่แล้ว

      Please check the file or folder name or its path for which you are running the command.

  • @orincywhytedesigns
    @orincywhytedesigns 2 ปีที่แล้ว

    Almost finished

  • @mohamedyoussef8835
    @mohamedyoussef8835 2 ปีที่แล้ว

    Awesome +++++++++++++++++ 😃

  • @Pareshbpatel
    @Pareshbpatel 8 วันที่ผ่านมา

    {2024-12-20}

  • @starlord7526
    @starlord7526 ปีที่แล้ว

    nothing understood tbh, all you did was write the code only

  • @hello0192
    @hello0192 2 ปีที่แล้ว +1

    wrost tutorial

  • @mohamedyoussef8835
    @mohamedyoussef8835 2 ปีที่แล้ว

    Awesome +++++++++++++++++ 😃

  • @mohamedyoussef8835
    @mohamedyoussef8835 2 ปีที่แล้ว

    Awesome +++++++++++++++++ 😃