
App.js:53
Uncaught TypeError: Cannot add property max_content_id, object is not extensible
else if(this.state.mode === 'create'){
_article = <CreateContent onSubmit={
function(_title, _desc) {
//setState()를 사용해 새로운 content추가
this.max_content_id = this.max_content_id+1;
//원본데이터를 바꾸지 않으면서 state에 추가하는 방법
var _contents = this.state.contents.concat({id: this.max_content_id, title:_title, desc:_desc})
this.setState(
{contents: _contents}
);
}
}></CreateContent>
}
function 뒤에 .bind(this) 빼먹어서 this.max__content_id를 제대로 못 가리킨 것이었음.
.bind(this) 추가해서 해결
this. 사용할 때는 제대로 가리키도록 바인딩 했는지 확인할 것
else if(this.state.mode === 'create'){
_article = <CreateContent onSubmit={
function(_title, _desc) {
//setState()를 사용해 새로운 content추가
this.max_content_id = this.max_content_id+1;
//원본데이터를 바꾸지 않으면서 state에 추가하는 방법
var _contents = this.state.contents.concat({id: this.max_content_id, title:_title, desc:_desc})
this.setState(
{contents: _contents}
);
}.bind(this)
}></CreateContent>
}