链接到GitHub上的该项目: https://github.com/sheedSVNTH/MERN-expense-manager-app
我收到错误:未捕获的TypeError:无法读取未定义的属性'setState'
我已经正确绑定了“ this”。这是我的代码段。
import React from 'react';
import {Button} from 'react-bootstrap';
import Modal from 'react-modal';
import axios from 'axios';
import {Link} from 'react-router-dom';
var querystring = require('querystring');
class Add extends React.Component {
constructor() {
super();
this.state = {
description: '',
amount: '',
month: '',
year: '',
messageFromServer: '',
modalIsOpen: false
}
this.handleSelectChange = this.handleSelectChange.bind(this);
this.onClick = this.onClick.bind(this);
this.handleTextChange = this.handleTextChange.bind(this);
this.insertNewExpense = this.insertNewExpense.bind(this);
this.openModel = this.openModal.bind(this);
this.closeModal = this.closeModal.bind(this);
}
openModal() {
this.setState({modalIsOpen: true});
}
closeModal() {
this.setState({
modalIsOpen: false,
description: '',
amount: '',
month: 'Jan',
year: 2018,
messageFromServer: ''
});
}