Using React.createRef
This commit is contained in:
parent
41f10c0dc3
commit
b9f6766a66
@ -18,6 +18,8 @@ const syntaxes = {
|
||||
class App extends React.PureComponent {
|
||||
state = {}
|
||||
|
||||
image = React.createRef()
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener('hashchange', this.handleHashChange);
|
||||
this.handleHashChange();
|
||||
@ -116,14 +118,12 @@ class App extends React.PureComponent {
|
||||
syntax,
|
||||
expr
|
||||
}, async () => {
|
||||
await this.image.doReflow();
|
||||
this.setSvgUrl(this.image.svg.current);
|
||||
this.setPngUrl(this.image.svg.current);
|
||||
await this.image.current.doReflow();
|
||||
this.setSvgUrl(this.image.current.svg.current);
|
||||
this.setPngUrl(this.image.current.svg.current);
|
||||
});
|
||||
}
|
||||
|
||||
imageRef = image => this.image = image
|
||||
|
||||
render() {
|
||||
const { svgUrl, pngUrl, permalinkUrl, syntax, expr, image } = this.state;
|
||||
const downloadUrls = [
|
||||
@ -146,7 +146,7 @@ class App extends React.PureComponent {
|
||||
<p>Sample warning message</p>
|
||||
</Message>
|
||||
{ image && <div className={ style.render }>
|
||||
<SVG data={ image } imageRef={ this.imageRef }/>
|
||||
<SVG data={ image } imageRef={ this.image }/>
|
||||
</div> }
|
||||
</React.Fragment>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user