简体   繁体   中英

React Higher Order Components Function argument

I don't understand the HOC example in the react docs when it comes to passing in the second argument, selectData. How is that function being passed and utilized,like just general flow of what is happening with selectData?

 const CommentListWithSubscription = withSubscription( CommentList, (DataSource) => DataSource.getComments() );

 // This function takes a component... function withSubscription(WrappedComponent, selectData) { //...and returns another component... return class extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.state = { data: selectData(DataSource, props) }; }

I finally understood. DataSource is a global. Calling SelectData will trigger the callback provided by the arrow function ie DataSource.getComments().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM