import React from 'react';

export class Checkbox extends React.PureComponent {

  handleToggle = () => {
    this.props.handleToggle(this.props.node);
  }

  render() {
    if (this.props.node.childKeys && this.props.node.childKeys.length) {
      let nodeList = this.props.node.childKeys.map(childNode => {
        return <Checkbox key={childNode.key} node={childNode} handleToggle={this.props.handleToggle} />;
      })
      return (
        <li>
          <input type='checkbox' checked={this.props.node.checked} className='pointer'
            onChange={this.handleToggle} />
          <label className='ml2'>{this.props.node.key}</label>
          <ul className='list'>
            {nodeList}
          </ul>
        </li>
      );
    } else {
      return (
        <li>
          <input type='checkbox' checked={this.props.node.checked} className='pointer'
            onChange={this.handleToggle} />
          <label className='ml2'>{this.props.node.key}</label>
        </li>
      );
    }
  }
}
import React from 'react';

export class Checkbox extends React.PureComponent {

  handleToggle = () => {
    const { node, handleToggle } = this.props;
    handleToggle(node);
  }

  render() {
    const { node, handleToggle } = this.props;
    if (node.childKeys && node.childKeys.length) {
      let nodeList = node.childKeys.map(childNode => {
        return <Checkbox key={childNode.key} node={childNode} handleToggle={handleToggle} />;
      })
      return (
        <li>
          <input type='checkbox' checked={node.checked} className='pointer'
            onChange={this.handleToggle} />
          <label className='ml2'>{node.key}</label>
          <ul className='list'>
            {nodeList}
          </ul>
        </li>
      );
    } else {
      return (
        <li>
          <input type='checkbox' checked={node.checked} className='pointer'
            onChange={this.handleToggle} />
          <label className='ml2'>{node.key}</label>
        </li>
      );
    }
  }
}
Use variables to cache values
Use variables to cache values
