Adrienne
Adrienne

Reputation: 2680

How do you declare a 'const' in react-native?

I keep getting an error SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

I think it is because I have a line like this:

    const shouldSet = touches.length === 1;
    if (shouldSet) {
      const { onPanBegin } = this.props;

Upvotes: 4

Views: 7678

Answers (3)

deju
deju

Reputation: 1028

you need get the lastest version of react-native.

pod 'React', '0.13.0-rc'

Upvotes: 0

Colin Ramsay
Colin Ramsay

Reputation: 16466

Update 2015-10-23: as of React Native v0.13.0-rc const is now enabled.

React Native's JavaScript environment is not a browser, instead it uses JavaScriptCore. Anything that isn't supported natively needs to be transformed down to a subset of JS that JavaScriptCore supports, and React Native uses Babel to do that. Here are the transformations that React Native uses (as of 2015-07-31):

ES5

  • Reserved Words: promise.catch(function() { });

ES6

  • Arrow functions
  • Call spread
  • Classes
  • Destructuring
  • Computed Properties
  • Object Consise Method
  • Object Short Notation
  • Rest Params
  • Template Literals:

ES7

  • Object Spread
  • Function Trailing Comma

It is not immediately clear to me why constants aren't included in this list, and it appears that support for overriding it still isn't quite ready:

https://github.com/facebook/react-native/issues/1451

Upvotes: 3

Yevgen Safronov
Yevgen Safronov

Reputation: 4033

At the moment const keyword is not supported in react-native android, I hope it will be available with the next release of react-native. The fix was trivial, for more details look into origin github issue.

Upvotes: 0

Related Questions