I have a JSX file MyComponent.jsx defined as below;
import compose from 'compose-function'
const MyComponent = () => {
//some hooks like useState, useEffect here
// finally returns some JSX
return (
<>
</>
)
}
function MyComponentData(props) {
let StyledMyComponent = compose(
withStyle(style),
withTranslation('translation'),
withMyApi()
)(MyComponent);
return (
<MyContextProvider>
<StyledMyComponent />
</MyContextProvider>
);
}
export default MyComponentData;
Now "withMyApi" looks like below (defined in separate Api.jsx file);
export function withMyApi() {
// Extra function wrapper. Is this required to compose multiple HOCs ?
return function(WrappedComponent) {
class MyApiURLs extends React.Component {
constructor(props) {
super(props);
this.api = {
dataSources: dataSources
}
}
render() {
const { title, content } = this.props;
return (
<div>
<WrappedComponent api={this.api} {...this.props} />
</div>
);
}
}
return MyApiURLs;
}
}
Now here are my questions;
- I am trying to understand the usage of "compose-function" dependency. Is it to compose things like styles, class to make API calls, translations, etc
- Inside withMyApi, I see an extra function wrapper. Is that required to compose multiple HOCs ? I mean the whole syntax is quite confusing. While I am aware about HOCs, just wanted to understand the syntax usage it his case and specifically in context of how it is consumed in MyComponent.jsx.
- What does the "WrappedComponent" refer to exactly in this case ? Is that what is in the next round brackets where I compose i.e. MyComponent in this case ?