redux中通过props传递action的疑问?

最近在用react + redux 做开发,遇到这样一个问题。
我从后台获取这样一组数据

[
    {
        type: 'button',
        ...
    },
    {
        type: 'text',
        ...
    }
]

然后通过统一的方法把数据渲染成自定义的Button和Text控件。
例如:

let component = components[type];
return React.createElement(component, {action1: action1, action2: action2});

现在的问题是:我有一些action是Button控件独有的,一些action是Text控件独有的,我在创建控件的时候要怎么设计才可以给不同的控件传递不同的action而不是把所有的action都传递给它们?

阅读 2.6k
1 个回答

既然都用 type 去取专门的组建了,就区分 type 传特定的 Action 呗。

let component = components[type];
let componentActions = actions[type];

return React.createElement(component, componentActions);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题