0

I would like to change my export { default } from 'MyFile' depending on certain conditions, so can I replace the file with a string variable?

Currently I have something like this:

let exportFrom
if(SOME_CONDITION) {
  exportFrom = '../Something/Blah'
} else {
   exportFrom = './SomethingElse'
}
export { default } from exportFrom

This currently doesn't work as I get:

Parsing error: Unexpected token

Is there a way to do this?

It is also important to note, that the reason I am doing this in the first place is because I am using nextjs, and one of my pages needs to be an error in certain conditions, otherwise it is just a react component which handles the content of it. So if this is not the way to do it, how do I solve my issue?

1

2 Answers 2

1

Simply export like this:

export default exportFrom

Or, using named export:

export {
  exportFrom,
  // you_can_export_any_number,
  // of_variables
}

For full reference see import and export

1

Just drop {}

export default exportFrom

Here's MDN ref

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.