Mathew
Mathew

Reputation: 1450

constants in react native

how can I create a constant in react native? I have considered putting it in state but this allows the value to be changed. Here is my code:

export default class test extends Component{
  constructor(props){
    this.state = {answer:42}   // I'd like answer to be a constant
  }
}

I normal java script I would use const answer = 42 however this doesn't work:

this.state = {const answer:42}

How can this be done? Thanks

PS:

I am looking for something similar to #define in C

Upvotes: 1

Views: 2046

Answers (1)

mxdi9i7
mxdi9i7

Reputation: 697

Use a .env file with your constants, and reference them by calling process.env.YOUR_KEY

You will likely need to install this package to extract the values from your .env file: dotenv packege on Github

Upvotes: 1

Related Questions