0
私はクラスのTourEditorを持ち、送信時にフォームを処理するtourEditorクラスの親です。残念ながら、子の初期状態を保存しているだけで、状態を更新していないのであれば、親のtourEditorがコンポーネントオブジェクトを更新するようにしたいと思います。どのようにこれを解決することができますか?子/親が状態を変更したときに親を更新します
TourEditor.js
export default class TourEditor extends React.Component {
constructor(props){
super(props);
this.state = {"files": []};
this.updateFiles = this.updateFiles.bind(this);
}
componentDidMount() {
tourEditor({ component: this });
}
updateFiles(files) {
this.setState({
files: files
});
}
render() {
const { tour } = this.props;
return (<form
ref={ form => (this.tourEditorForm = form) }
onSubmit={ event => event.preventDefault() }
>
<FormGroup>
//....
</FormGroup>
</form>);
}
}
tourEditor.js
export default function tourEditor(options) {
console.log(options);
component = options.component;
validate();
}
あなたは 'updateFiles'呼び出すところ、私は見ていない、あなたもそれを含める必要があります – Khang