// before
module.exports = require('./inner.js');
// nowadays
export default from './inner.js';
i'm trying to do this, but babel allow it only in es7 stage 1 as it is proposal for now. So for now, im stick to these two lines:
import sticker from './box-sticker.jsx';
export default sticker;
Can I shorter them to one?
One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() cannot be called conditionally, it always runs at the beginning of the file. To use the require() statement, a module must be saved with . js extension as opposed to .
The export statement is used when creating JavaScript modules to export objects, functions, variables from the module so they can be used by other programs with the help of the import statements. There are two types of exports. One is Named Exports and other is Default Exports.
You should be able to do
export {default as default} from './inner.js';
// or even
export {default} from './inner.js';
with current ES6 semantics.
However I don't think there's anything wrong with using the ES next proposal, I'm pretty confident that it will make it into ES7 ES8.
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