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.
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.
While React Native is built in Flow, it supports both TypeScript and Flow by default.
const is a new keyword in ES6+. Values assigned to it cannot be changed, however, lists and dictionaries can be.
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.
The const is inside a class. Move it outside the class and all will be ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With