简体   繁体   中英

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' ? 😊

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM