Advertisement

@reduxjs/toolkit和zustand使用方法

阅读量:

一、reduxjs/toolkit

store/count.ts模块创建

复制代码
 import { createSlice } from "@reduxjs/toolkit";

    
  
    
 const counterStore = createSlice({
    
   name: "counter",
    
   initialState: {
    
     count: 0,
    
   },
    
   reducers: {
    
     increment: (state) => {
    
       state.count++;
    
     },
    
     decrement: (state) => {
    
       state.count--;
    
     },
    
     add_num: (state, action) => {
    
       state.count += action.payload;
    
     }
    
   }
    
 });
    
  
    
 export const { increment, decrement, add_num } = counterStore.actions

全部评论 (0)

还没有任何评论哟~