I'd like to the following but with a single line, if possible:
import Module from './Module/Module;'
export Module;
I tried the following but it doesn't seem to work:
export Module from './Module/Module;
I'd like to the following but with a single line, if possible:
import Module from './Module/Module;'
export Module;
I tried the following but it doesn't seem to work:
export Module from './Module/Module;
export {default as Module} from './Module/Module';
is the standard ES6 way, as long as you don't need Module
to also be available inside the module doing the exporting.
export Module from './Module/Module';
is a proposed ESnext way to do it, but that only works if you've enabled it in Babel for now.
component
is now read-only and unable to be hot reloaded. Very strange! –
Becalm export-extensions
here - babeljs.io/docs/plugins/transform-export-extensions –
Francklin export { default as default } from
or export { default } from
–
Paschasia export {default as Module} from './Module/Module';
Module is not defined in current file 🤷♂️ –
Bennington I don't know why but just this works for me :
components/index.js:
import Component from './Component';
import Component2 from './Component2';
import Component3 from './Component3';
import Component4 from './Component4';
export {Component, Component2, Component3, Component4};
I import the exports like this :
import {Component, Component2, Component3, Component4} from '../components';
Please note you can also re-export everything from a module:
export * from './Module/Module';
For React Native components this syntax works for me:
export {default} from 'react-native-swiper';
// Service
// ...
export const paymentService = new PaymentService()
// Entry services/index.js file
export * from './paymentService'
// use it like
import { paymentService } from './services/'
export {Module as default} from '/path'
that worked for me with Module as named exported.
export {default} from '/path'
if Module is exported as default from the file where defined
So, I've found this to work quite well for the immediate export functionality of having an index.js
at the root of the components
directory for easy referencing:
import Component from './Component/Component'
import ComponentTwo from './ComponentTwo/ComponentTwo'
module.exports = {
Component,
ComponentTwo
};
You need to use module.exports
.
Component
will no longer be a reference to your exported component, but instead will be an object, with your instance reference living on Component.default
–
Greig module.exports
? I like this method of packaging a bunch of components into an index.js
but can't figure out the syntax. import x from 'x'; import y from 'y'; export default {x, y};
then import {x} from xy;
doesn't work (and I can't figure out why not) –
Depressor export {x, y}
instead? –
Podvin © 2022 - 2024 — McMap. All rights reserved.
module.exports = require('./inner.js')
? and Isexport { foo as default }
valid ES6? – Margarine