Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

const can only be used in a .ts file react native

const ACCESS_TOKEN = 'access_token';  react-native-cli: 2.0.1 react-native: 0.47.2 

I am watching a tutorial video in which the expert get the value from the api and stored it inside the const ACCESS_TOKEN but when i am doing it in my code it gives me an error

const can only be used in a .ts file react native

Please suggest.

like image 572
Anuj Dahiya Avatar asked Aug 28 '17 10:08

Anuj Dahiya


People also ask

What is const in react native?

The const keyword is used when you want to create a Constant variable. Constants are like the variables you are probably used to, except they cannot be modified. It's being used here because the variable is not being changed inside the render method of your component.

Does react native use TypeScript?

While React Native is built in Flow, it supports both TypeScript and Flow by default.

Can I use const in React?

const is a new keyword in ES6+. Values assigned to it cannot be changed, however, lists and dictionaries can be.

What is TSX in React?

tsx . This is the extension that you should use anytime you include the JSX syntax in a React component file. You also need the jsx set to true which is done by default. TypeScript is able to compile JSX directly into JavaScript. For more information, you can review the TypeScript docs on JSX.


1 Answers

The const is inside a class. Move it outside the class and all will be ok.

like image 143
pashute Avatar answered Oct 10 '22 02:10

pashute