React: “this” is undefined inside a component function

前端 未结 10 2136
春和景丽
春和景丽 2020-11-22 04:59
class PlayerControls extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      loopActive: false,
      shuffleActive: false,
    }         


        
10条回答
  •  不思量自难忘°
    2020-11-22 05:48

    If you are using babel, you bind 'this' using ES7 bind operator https://babeljs.io/docs/en/babel-plugin-transform-function-bind#auto-self-binding

    export default class SignupPage extends React.Component {
      constructor(props) {
        super(props);
      }
    
      handleSubmit(e) {
        e.preventDefault(); 
    
        const data = { 
          email: this.refs.email.value,
        } 
      }
    
      render() {
    
        const {errors} = this.props;
    
        return (
          
    ) } }

提交回复
热议问题