我收到此错误Uncaught TypeError:每当我在AuthorForm的输入框中输入任何内容时,都无法读取未定义的属性'state'.我正在使用React和ES7.
在ManageAuthorPage中的setAuthorState函数的第3行发生错误.即使我在setAuthorState中放置了console.log(this.state.author),它也会停在console.log并调出错误.
无法通过互联网找到其他人的类似问题.
这是ManageAuthorPage代码:
import React, { Component } from 'react';
import AuthorForm from './authorForm';
class ManageAuthorPage extends Component {
state = {
author: { id: '', firstName: '', lastName: '' }
};
setAuthorState(event) {
let field = event.target.name;
let value = event.target.value;
this.state.author[field] = value;
return this.setState({author: this.state.author});
};
render() {
return (
<AuthorForm
author={this.state.author}
onChange={this.setAuthorState}
/>
);
}
}
export default ManageAuthorPage
Run Code Online (Sandbox Code Playgroud)
这是AuthorForm代码:
import React, { Component } …Run Code Online (Sandbox Code Playgroud) 嘿伙计们在这里遇到的问题是方法没有以正确的顺序发射.我无法弄清楚如何this.props.history.pushState(null, '/authors');在saveAuthor()方法中进行等待.
将非常感谢帮助.
import React, { Component } from 'react';
import AuthorForm from './authorForm';
import { History } from 'react-router';
const source = 'http://localhost:3000/authors';
// History Mixin Component Hack
function connectHistory (Component) {
return React.createClass({
mixins: [ History ],
render () {
return <Component {...this.props} history={this.history}/>
}
})
}
// Main Component
class ManageAuthorPage extends Component {
state = {
author: { id: '', firstName: '', lastName: '' }
};
setAuthorState(event) {
let field = event.target.name;
let value …Run Code Online (Sandbox Code Playgroud)