class SelectableItem extends React.Component { constructor() { super(); this.handleOnPress = this.handleOnPress.bind(this); } shouldComponentUpdate(nextProps) { const { isSelected } = this.props; return isSelected !== nextProps.isSelected; } handleOnPress() { const { onPress } = this.props; onPress(); } render() { const { isSelected, text } = this.props; const textColor = isSelected ? 'blue' : 'black'; return ( {text} ); } } class SelectList extends React.Component { constructor() { super(); this.handleOnPressItem = this.handleOnPressItem.bind(this); this.state = { selected: new Map(), }; } onPressItem(id) { this.setState((state) => { const selected = new Map(state.selected); selected.set(id, !selected.get(id)); return { selected }; }); } renderItem({ item }) { const { selected } = this.state; return ( ); } render() { const { data } = this.props; return ( item.id} renderItem={this.renderItem} /> ); } }