Skip to content

Commit

Permalink
fix ref bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Nov 8, 2018
1 parent 1a46020 commit 569baed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/ReactKonva.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var Stage = function (_React$Component) {
container: this._tagRef
});

this.props.forwardedRef(this._stage);
this.props.forwardedRef && this.props.forwardedRef(this._stage);

applyNodeProps(this._stage, this.props);

Expand All @@ -62,7 +62,7 @@ var Stage = function (_React$Component) {
if (!Konva.isBrowser) {
return;
}
this.props.forwardedRef(this._stage);
this.props.forwardedRef && this.props.forwardedRef(this._stage);
applyNodeProps(this._stage, this.props, prevProps);

KonvaRenderer.updateContainer(this.props.children, this._mountNode, this);
Expand All @@ -72,7 +72,7 @@ var Stage = function (_React$Component) {
if (!Konva.isBrowser) {
return;
}
this.props.forwardedRef(null);
this.props.forwardedRef && this.props.forwardedRef(null);
KonvaRenderer.updateContainer(null, this._mountNode, this);
this._stage.destroy();
};
Expand Down
6 changes: 3 additions & 3 deletions src/ReactKonva.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Stage extends React.Component {
container: this._tagRef
});

this.props.forwardedRef(this._stage);
this.props.forwardedRef && this.props.forwardedRef(this._stage);

applyNodeProps(this._stage, this.props);

Expand All @@ -47,7 +47,7 @@ class Stage extends React.Component {
if (!Konva.isBrowser) {
return;
}
this.props.forwardedRef(this._stage);
this.props.forwardedRef && this.props.forwardedRef(this._stage);
applyNodeProps(this._stage, this.props, prevProps);

KonvaRenderer.updateContainer(this.props.children, this._mountNode, this);
Expand All @@ -57,7 +57,7 @@ class Stage extends React.Component {
if (!Konva.isBrowser) {
return;
}
this.props.forwardedRef(null);
this.props.forwardedRef && this.props.forwardedRef(null);
KonvaRenderer.updateContainer(null, this._mountNode, this);
this._stage.destroy();
}
Expand Down
15 changes: 15 additions & 0 deletions tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ describe('Test references', function() {
const stageRef = instance.stage;
expect(stageRef instanceof Konva.Stage).to.equal(true);
});

// how can we make this work?
it('works ok with no ref', function() {
class App extends React.Component {
render() {
return (
<Stage width={300} height={300}>
<Layer ref={node => (this.layer = node)} />
</Stage>
);
}
}
const wrapper = mount(<App />);
instance = wrapper.instance();
});
});

describe('Test stage component', function() {
Expand Down

0 comments on commit 569baed

Please sign in to comment.