As far as I understand and, following the documentation, a HOC is a function that takes a component and returns a new component. An example of that is the function connect from react-redux:
connect(mapStateToProps, mapDispatchToProps)(MyComponent)
I was using Autosizer
from React-virtualized
and found the next definition in its documentation:
High-order component that automatically adjusts the width and height of a single child.
The syntax example used in its documentation is the next one:
ReactDOM.render(
<AutoSizer>
{({height, width}) => (
<List
height={height}
rowCount={list.length}
rowHeight={20}
rowRenderer={rowRenderer}
width={width}
/>
)}
</AutoSizer>,
document.getElementById('example'),
);
Not sure if I am asking below the appropriate questions that allow me to understand what is going on. If not, I ask you to forget about those two questions and explain it in a different approach.
1) Why is Autosizer a HOC? I cannot tell it is a function receiving one component and returning another one the same way as connect in react-redux.
2) In the anonymous function ({height, width}) => {...}
, height and width are properties of an object being passed. Which object and where does it come from?