有没有办法在一次导出中导出具有或不具有hoc的组件?我知道我可以这样做:
export const TranslatedList = translate('components')(List);
export const PureList = List;
但是还有其他方法可以执行以下操作:
export {
TranslatedList: translate('components')(List),
PureList: List,
};
和index.js中的内容类似:
import { TranslatedList } from './List';
export default TranslatedList;
也许是个愚蠢的问题,但这对我很有帮助
答案 0 :(得分:0)
也许像这样使用node.js本地导出:
module.exports = {
TranslatedList: translate('components')(List),
PureList: List,
};
并要求它
const {TranslatedList, PureList} = require('list.js');
答案 1 :(得分:0)
在ES6中,你根本无法做到这一点:
export {
TranslatedList: translate('components')(List),
PureList: List,
};
相反,您可以尝试这样做:
const toExport = {
TranslatedList: translate('components')(List),
PureList: List,
};
export toExport;
要导入,只需执行以下操作:
import { TranslatedList, PureList } from './list.js';
答案 2 :(得分:0)
派对有点晚了。我没有找到这个问题的“好”解决方案,但在我看来这是一个“好”的解决方案。
const TranslatedDropzone = translate()(Dropzone)
const TranslatedDropzoneControls = translate()(DropzoneControls)
const TranslatedDropzonePreview = translate()(DropzonePreview)
const TranslatedFilePreview = translate()(FilePreview)
export {
TranslatedDropzone as Dropzone,
TranslatedDropzoneControls as DropzoneControls,
TranslatedDropzonePreview as DropzonePreview,
TranslatedFilePreview as FilePreview
}
export default TranslatedDropzone