为什么只在App.js中实现本例子好用,新建其他的JS文件中不能用?
import React from 'react';
import './SubApp.css'
import CommentBox from './components/CommentBox';
import CommentList from './components/CommentList';
class SubApp extends React.Component{
constructor(props){
super(props);
this.state = {
comments:['This is my first replay']
};
this.addComment = this.addComment.bind(this);
}
addComment(msg){
this.setState({
comments:[...this.comments,msg]
});
}
render(){
const {comments} = this.state;
return(
<div className="SubApp">
<span>TEST</span>
<CommentList messages={comments}/>
<CommentBox
commentsLength={comments.length}
onAddComment={this.addComment}
/>
</div>
);
}
}
export default SubApp;