【问题标题】:React: export function with connected functionReact:具有连接功能的导出功能
【发布时间】:2018-11-23 19:21:01
【问题描述】:

我知道如何以这种方式将我的翻译功能连接到组件:

class App extends Component {
...
}
export default translate('common')(App);

但是,如果以这种方式导出组件,我该如何做同样的任务:

export function UserInterface({data, onAdmin, isAdmin}: propTypes){
...

我知道,这是一个愚蠢的问题。但我被困在这一点上。

【问题讨论】:

    标签: javascript reactjs function export components


    【解决方案1】:

    你可以这样写:

    export const UserInterfaceWithTranslation = translate('common')(UserInterface);
    

    请阅读更多关于exports的信息。

    【讨论】:

    • 谢谢!真的很有帮助!
    【解决方案2】:

    你也可以导出函数

    MyContext.js

    function UserInterface({data, onAdmin, isAdmin}: propTypes){ 
     ... some code
    }
    
    module.exports = {
     userInterface : UserInterface
    }
    

    导入

    import myContexts from './MyContext'
    
    myContexts.userInterface(params);
    

    【讨论】:

      猜你喜欢
      • 2020-05-30
      • 2020-08-14
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 2021-01-29
      • 1970-01-01
      • 2013-03-15
      相关资源
      最近更新 更多