简体   繁体   English

React HOC 无箭头 function 语法

[英]React HOC without arrow function syntax

I have a HOC React function written in es6 syntax like so:我有一个用 es6 语法编写的 HOC React function,如下所示:

const withHOC = Component => (props) => {
  return (
    <Component
      {...props}
    />
  );
};

How can I write this in es5 syntax?我怎样才能用 es5 语法写这个?

eg: function HOC(){}例如: function HOC(){}

given HoC or HoF definitions, will be a function that returns another component/function给定 HoC 或 HoF 定义,将是返回另一个组件/功能的 function

if i understand correctly, maybe what you want is:如果我理解正确,也许你想要的是:

function withHoC(Component) {
  return function(props) {
    return <Component {...props} />
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM