Well I wonder, why, in react, we often see higher order components of the form:
MyComponent = withSomeHOC(params)(function MyActualCompoent(props) {
return <div/>
})
And the implementation might look like:
function withSomeHOC(params, modifier) {
function(WrappedComponent) {
return function(props) {
//do whatever to modify something based on params.
const data = modifier(React.useContext(someCTX));
return <>
<div>{data}</div>
<WrappedComponent {...props}/>
</>;
}
}
}
Instead of the more logical approach (to me) to just add params as second (and third) parameter to the higher order component itself:
MyComponent = withSomeHOC(function MyActualComponent(props) {
return <div/>
}, params, modifier);
function(WrappedComponent, params, modifier) {
return function(props) {
//do whatever to modify something based on params.
const data = modifier(React.useContext(someCTX));
return <>
<div>{data}</div>
<WrappedComponent {...props}/>
</>;
}
}
Why do we hardly see the second approach and nearly always the first? What is the disadvantage of the second? An advantage is a more simple program structure, instead of deeply nested higher order components and functions.