mobx: MobX 5.5 + React Native + @computed RangeError: Maximum call stack size exceeded
Hi, I got react native and typescript running, updated the JSC (altered gradle build config) to the latest version to support MobX 5 (installed via npm). Everything works fine except for @computed
@observer
export default class App extends Component<Props> {
@observable public countVal:number = 0;
constructor(props, context){
super(props, context);
this.onPressLearnMore = this.onPressLearnMore.bind(this);
this.countVal = 0;
}
componentDidMount(){
console.log('started!');
}
onPressLearnMore(){
this.countVal = this.countVal + 1;
console.log(this.countVal);
}
@computed get twoX(){
return this.countVal * 2;
}
render() {
console.log('rendered!');
return (
<View style={styles3.container}>
<Text style={styles3.welcome}>Welcome to react!</Text>
<Text className={styles2.blue}>Welcome {this.countVal} & {this.twoX}</Text>
<Text style={styles3.instructions}>{instructions}</Text>
<Button
onPress={this.onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
</View>
);
}
}
This produces the error:
RangeError: Maximum call stack size exceeded
The stack trace is full of "get"calls in mobx.module.js:295:20 , so it means get is being run recursively.
- Downgrading to MobX v4.4 fixes the issue
Thanks
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 35 (17 by maintainers)
Commits related to this issue
- Fixed stack overflow for @computed on RN, fixes #1777 — committed to mobxjs/mobx by mweststrate 6 years ago
- Merge pull request #1826 from mobxjs/fix-computed-stack-overflow Fixed stack overflow for @computed on RN, fixes #1777 — committed to mobxjs/mobx by mweststrate 6 years ago
- Fixed stack overflow for @computed on RN, fixes #1777 — committed to mobxjs/mobx by mweststrate 6 years ago
Fixed and released as 5.7.0
Here is a minimal project reproducing the issue: https://github.com/Jakst/break-mobx5-computed-react-native https://expo.io/@jakst/expomobxcomputed
Note that mobx 4 is just as actively maintained! Every new feature was and will be backported.
Op za 13 okt. 2018 18:15 schreef xfactor5 notifications@github.com: