我使用Flux构建我的应用程序,然后出现一个问题使我感到困惑:“如何在助焊剂中创建通用组件?”。

首先,“通用组件”是指像Facebook上的“ Like button”之类的组件,不仅有一个项目使用此组件。

并且组件具有“商店”,“动作”,“视图(反应组件)”,“商店”为应用程序的Dispatcher导出“ dispatchToken”。但是“ Action”部分需要使用Dispatcher,并且使用“ Dispather.handleViewAction”。
但是在组件的上下文中,我们不知道什么是Dispatcher。

在您的应用程序中,如何创建通用组件?或者您知道Facebook小组是如何创建它的?

最佳答案

是的,通用组件不应依赖于actionCreators。您可以在父组件中定义回调,然后从公共组件中调用它们(通过this.props)。这些回调函数可以随后调用actionCreators

父应用的特定组件:

render :

   <CommonButton  onClick={ this.onCommonButtonClick } >


onCommonButtonClick:

   MyActionCreator.createAction(...);


CommonButton:

render :

  <button onClick={ this.props.onClick }>

10-05 20:36
查看更多