0
私は反応があり、状態が変化するたびにキャンバスを反応させてレンダリングしようとしています。リアクションレンダリング/更新キャンバス
//set initial state
constructor(props) {
super(props);
this.state = {
imgFile: this.props.imgFile,
show: false
};
}
//The render canvas
render() {
return (
<div className="col-sm-4">
<canvas ref={(c) => { this.myCanvas = c; }} />
</div>
);
}
私の質問です:小道具でキャンバスを更新する方法はありますか?これまでのところ、私はこれだ:
componentDidMount() {
const origin = this.state.imgFile;
// canvas area/img calculations
this.funcForDrawCanvas(origin.path, origin.presition, origin.height, origin.width);
}
をそれがマウントされてコンポーネントきた後、それ以上の任意のアイデアを、それを更新しませんか?またはキャンバスタグを削除し、状態が変更されたときに再度挿入する方法はありますか?
各コンポーネントの仕様が何であるかを必ず確認してください。これを達成する方法はたくさんありますが、['componentDidMount'](https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount)でキャンバスを初期化する方法、 ['shouldComponentUpdate'](https://facebook.github.io/react/docs/component-specs.html#updating-shouldcomponentupdate)、[' componentDidUpdate'](https://facebook.github.io)でキャンバスレンダリングを行います/react/docs/component-specs.html#updating-componentdidupdate)。 – Dom
@Dom imgでキャンバスを再描画する方法の例を教えていただけますか? –