Skip to content

Commit 493e532

Browse files
authored
Merge pull request #34 from prayuditb/master
fix crash because unregisterStep called after component unmounted
2 parents adc3039 + 50df03f commit 493e532

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/hocs/copilot.js

Lines changed: 13 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,14 @@ const copilot = ({
149154
});
150155
}
151156

157+
componentDidMount() {
158+
this.mounted = true;
159+
}
160+
161+
componentWillUnmount() {
162+
this.mounted = false;
163+
};
164+
152165
render() {
153166
return (
154167
<View style={{ flex: 1 }}>

0 commit comments

Comments
 (0)