I am trying to understand the basic syntax of a React HOC. Consider below example;
//WithLoading.js
import React from 'react';
function WithLoading(Component) {
return function WithLoadingComponent({ isLoading, ...props }) {
if (!isLoading) return <Component {...props} />;
return <p>Hold on, fetching data might take some time.</p>;
};
}
export default WithLoading;
And it is invoked/used as below;
const ListWithLoading = WithLoading(List);
render() {
return (
<ListWithLoading
isLoading={this.state.loading}
repos={this.state.repos}
/>
);
}
Now my specific question is -
When we invoke the function WithLoading(), it actually returning an inner function (WithLoadingComponent). So if the returned thing i.e. ListWithLoading is a function and not a component, how are we able to use it as a component i.e.
<ListWithLoading
isLoading={this.state.loading}
repos={this.state.repos}
/>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…