Skip to content

Commit 1b676a4

Browse files
committed
fix crash because unregisterStep called after component unmounted
1 parent bb377b7 commit 1b676a4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/hocs/copilot.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const copilot = ({
7878

7979
startTries = 0;
8080

81+
mounted = false;
82+
8183
eventEmitter = mitt();
8284

8385
isFirstStep = (): boolean => this.state.currentStep === this.getFirstStep();
@@ -94,6 +96,9 @@ const copilot = ({
9496
}
9597

9698
unregisterStep = (stepName: string): void => {
99+
if (!this.mounted) {
100+
return;
101+
}
97102
this.setState(({ steps }) => ({
98103
steps: Object.entries(steps)
99104
.filter(([key]) => key !== stepName)
@@ -149,6 +154,15 @@ const copilot = ({
149154
});
150155
}
151156

157+
componentDidMount() {
158+
this.mounted = true;
159+
}
160+
161+
componentWillUnmount() {
162+
console.log('componentWillUnmount method')
163+
this.mounted = false;
164+
};
165+
152166
render() {
153167
return (
154168
<View style={{ flex: 1 }}>

0 commit comments

Comments
 (0)