setState 會觸發 state update,
因此 render() 會再被叫起來,
你需要的是在 Switch class 裡加上 shouldComponentUpdate(nextProps, nextState)
根據 React life cycle 這 function 會在 render() 之前決定是否真的要re-render。
retrun true 就是要re-render
以下是程式碼
class Button extends React.Component {
render() {
return <div className="btn">button</div>
}
}
class Switch extends React.Component {
constructor(props) {
super(props);
this.state = store.getState().data[this.props.index];
}
//