사용자가 이전에 작성한 블로그를 편집 할 수 있도록 양식을 미리 채워야합니다. 나는 이것을 React에서하는 최선의 방법을 찾고있다. 현재 소품을 통해 구성 요소에 값을 전달하고 상태 속성을 소품 속성과 동일하게 설정했지만 반 패턴이라고 읽었습니다. 나는 '진리의 원천'을 이해한다. 그러나 그것을하는 더 좋은 방법은 무엇입니까? 나는 오히려 redux-form을 사용하지 않을 것이다. 아래는 내 제목 구성 요소이며 아래는 부모로부터 호출하는 방법입니다. 이 모든 것이 작동하지만 더 좋은 방법이 있습니까? 주 재산을 소품 속성으로 설정하지 않으려면 어떻게해야합니까? 부모로부터React - pre-populate form
import React, { Component, PropTypes} from 'react';
export default class DocumentTitle extends Component{
constructor(props) {
super(props);
this.state = {inputVal:this.props.publication.document_title}
this.handleChange = this.handleChange.bind(this)
}
handleChange(event) {
this.setState({inputVal: event.target.value});
}
componentWillReceiveProps(nextProps){
this.setState({inputVal: nextProps.publication.document_title})
}
render(){
return (
<div >
<label>Title</label>
<div>
<input onChange={this.handleChange} id="doc_title" type="text" value={this.state.inputVal}/>
</div>
</div>
)
}
}
전화 :
<DocumentTitle publication={this.props.publication} />
괜찮아 보입니다. 아약스 호출이 있으면 redux는 매우 편리합니다. – vijayst