【问题标题】:Easy-Peasy access other modelsEasy-Peasy 访问其他型号
【发布时间】:2021-03-09 08:51:10
【问题描述】:

我正在使用easy-peasy 作为 React 应用程序的状态管理器 在actionOn 中我需要访问另一个模型的状态,如何访问notes.onAddNote 中的todos.items

import { createStore, StoreProvider, action, actionOn } from 'easy-peasy';

const todos= {
  items: [],
  addTodo: action((state, text) => {
    state.items.push(text)
  })
};

const notes = {
  items: [],
  addNote: action((state, text) => {
      state.items.push(text)
  }),
  onAddNote: actionOn(
    (actions, storeActions) => storeActions.notes.addNote,
    (state, target) => {
        // HOW TO READ todos items
    }
  ),
};

const models = {
   todos,
   notes 
};

const store = createStore(models);

【问题讨论】:

    标签: javascript reactjs easy-peasy


    【解决方案1】:

    将 onAddNote 设为 thunkOn 而不是 actionOn

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多