Home > Software engineering >  React HOC without arrow function syntax
React HOC without arrow function syntax

Time:01-28

I have a HOC React function written in es6 syntax like so:

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

How can I write this in es5 syntax?

eg: function HOC(){}

CodePudding user response:

given HoC or HoF definitions, will be a function that returns another component/function

if i understand correctly, maybe what you want is:

function withHoC(Component) {
  return function(props) {
    return <Component {...props} />
  }
}
  •  Tags:  
  • Related