Say, I have an object like {foo: 5, bar: 10}
and I wanna export foo
and bar
from it separately, then when I do
import {foo} from './path/to/file';
I could get foo
equal to 5
, as if I did
export const foo = 5;
export const bar = 10;
How can I do it?
Exported values need their own top-level variable name. The easiest option might be something like this:
const obj = {foo: 5, bar: 10};
export const {foo, bar} = obj;
Really though, if the object is already declared in the file, you may be better off declaring the exports with the values directly.
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