Skip to content

Commit 660e317

Browse files
committed
fix(UIView): apply exit hook only on class components
fixes #71
1 parent 7e468bb commit 660e317

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/components/UIView.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,16 @@ export class UIView extends Component<UIViewProps, UIViewState> {
154154
this.uiViewAddress &&
155155
this.uiViewAddress.context &&
156156
this.uiViewAddress.context.name;
157-
props.ref = c => {
158-
this.componentInstance = c;
159-
this.registerUiCanExitHook(stateName);
160-
};
157+
158+
// only class components can implement the
159+
// uiCanExit hook and ref doesn't work on
160+
// stateless function components
161+
if(typeof component !== 'string' && !!component.prototype.render) {
162+
props.ref = c => {
163+
this.componentInstance = c;
164+
this.registerUiCanExitHook(stateName);
165+
};
166+
}
161167

162168
let child =
163169
!loaded && isValidElement(children)

0 commit comments

Comments
 (0)