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

Most upvoted comments

Fixed and released as 5.7.0

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:

and by the way, the reason I fell for MobX was the decorator syntax and I am very uncomfortable ditching that!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx/issues/1777#issuecomment-429554173, or mute the thread https://github.com/notifications/unsubscribe-auth/ABvGhOARN_NVceXVWwTJbFDN277zCHcrks5ukhGPgaJpZM4XahkD .