【问题标题】:What is the correct syntax to make them work together?使它们一起工作的正确语法是什么?
【发布时间】:2019-03-22 04:32:26
【问题描述】:

我仍然熟悉 react+redux 和 ES6。我正在尝试实现 i18n,但遇到了必须使用我的 redux 连接导出 i18n 翻译的问题。

export default connect(mapStateToProps, matchDispatchToProps)(UserList);

export default translate("translations")(UserList);

【问题讨论】:

  • 嗨!请拿起tour(你会得到一个徽章!),看看周围,通读help center,特别是How do I ask a good question? “我遇到了必须用我的redux导出i18n翻译的问题连接” 具体是什么问题?
  • 我在我的组件导出默认连接中有这个(mapStateToProps,matchDispatchToProps)(UserList);并且想添加这个也导出默认翻译(“翻译”)(用户列表);

标签: javascript reactjs redux


【解决方案1】:

你的问题不是特别清楚。我的理解是您正在尝试将 i18n 和 redux 一起使用。您需要使用 Compose 将它们拼接在一起。

import { ..., compose } from 'redux'

compose(
  connect(...),
  translate("translations")
)(MyComponent)

https://redux.js.org/api/compose

【讨论】:

    【解决方案2】:

    我认为你只export default 一次。并且您可以export 多种功能。例如export function Example(){}

    【讨论】:

      【解决方案3】:

      版本 1:

      export default translate('translations')(connect(mapStateToProps, matchDispatchToProps))(UserList)
      

      版本 2: (但我不确定 lodash compose 是否仍然存在) 从 'lodash' 导入 { compose };

      export default compose(
        translate('translations'),
        connect(mapStateToProps, matchDispatchToProps),
      )(UserList);
      

      你可能也对recompse这样的包感兴趣

      【讨论】:

        【解决方案4】:

        你试过了吗:

        export default translate("translations")(connect(mapStateToProps, matchDispatchToProps)(UserList));
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-12-12
          • 1970-01-01
          • 2021-07-21
          • 1970-01-01
          • 1970-01-01
          • 2014-06-18
          • 2013-11-21
          相关资源
          最近更新 更多