mobx-react icon indicating copy to clipboard operation
mobx-react copied to clipboard

@observer got an syntax error

Open zcgong opened this issue 10 years ago • 7 comments

I got this syntax error for use mobx-react in react-native. Anyone know what's happened ? 2955d7b5-0ba7-46c7-8cdc-45511b10e8ee

This is my code

MobxDemoRN 2.zip

zcgong avatar Aug 24 '16 02:08 zcgong

Not familiar with RN projects setup, but where is the babel configuration? .babelrc or something like that

mweststrate avatar Aug 24 '16 11:08 mweststrate

@mweststrate, people are usually using react native packager, with exclusive (babel-preset-react-native)[https://github.com/facebook/react-native/blob/master/babel-preset/configs/main.js], I'l try to check @Zcgong's example

andykog avatar Aug 24 '16 12:08 andykog

@Zcgong, I see you are using decorators without any configuration for that. I, personally, haven't managed to get it working with react native packager. And they saying that decorators won't work until T2645 lands in Babel. So thats not a mobx issue.

After 2 chages you app is working for me:

// before:
@observer
export default class App extends Component {
}

// after:
class App extends Component {
}
export default observer(App);

// before:
@list = []

// after:
  constructor() {
    extendObservable(this, {
      list: [],
    });
  }

andykog avatar Aug 24 '16 12:08 andykog

@andykog Thanks ! I will try this.

zcgong avatar Aug 25 '16 01:08 zcgong

@andykog Thanks a lot ! I fix this by two way:

  1. add .babelrc file add plugins "transform-decorators-legacy"
  2. your way

but I feel confuse with the first way, did it must add at the project init ? I try to add it in my current project but it not works. Then I init a new project and add it then copy code to this new , it works. Why ?

zcgong avatar Aug 25 '16 01:08 zcgong

@Zcgong, I guess, your last question is about react-native packager, not mobx-react. Try to google react-native packager transform-decorators-legacy

andykog avatar Oct 14 '16 14:10 andykog

Thankyou all sir, is working..

aryejfa avatar Apr 02 '18 01:04 aryejfa