用到的方法很简单,ES6 Object Destructuring.
import React from 'react'; import ReactDOM from 'react-dom'; import { connect } from 'react-redux'; //Import scss import './scss/btn.scss'; //Component A class Btn extends React.Component { clickHandler = () => { const { sign , dispatch } = this.props; if(sign == '+') dispatch({type:'INCREASE_COUNT'}); if(sign == '-') dispatch({type:'DECREASE_COUNT'}); } render() { const sign = this.props.children; return ( <div className="btnWrap"> <button onClick={this.clickHandler}> { sign } </button> </div> ) } }; export default connect()(Btn);