I get this straight from the documents of the eslint plugin "jsx-no-bind" , and it mentions one of the possible solutions for decreasing the number:
A common example of using bind in rendering is list rendering to have a separate callback for the list item:
var List = React.createClass({ render() { return ( <ul> {this.props.items.map(item => <li key={item.id} onClick={this.props.onItemClick.bind(null, item.id)}> ... </li> )} </ul> ); } });
Instead of doing it this way, pull the repeating section into your own component:
var List = React.createClass({ render() { return ( <ul> {this.props.items.map(item => <ListItem key={item.id} item={item} onItemClick={this.props.onItemClick} /> )} </ul> ); } }); var ListItem = React.createClass({ render() { return ( <li onClick={this._onClick}> ... </li> ); }, _onClick() { this.props.onItemClick(this.props.item.id); } });
This will speed up the rendering, since it avoids the need to create new functions (via bind calls) for each rendering.
ac_fire
source share