Loren
Loren

Reputation: 14856

How do I change the value of an imported variable?

import Foo from 'file'

if (inDevelopment) {
  Foo = null
}

I would like to do this, but it results in

SyntaxError: "Foo" is read-only

Is there anything that changes the default const behavior, like let import Foo from 'file'? 😊

Upvotes: 0

Views: 1608

Answers (1)

Bergi
Bergi

Reputation: 664503

You don't. Use a second variable:

import Foo from 'file'

const LocalFoo = inDevelopment ? null : Foo;

Only the module that exported the variable can change its value, although non-constant exports are weird to work with.

Upvotes: 3

Related Questions