[英]React - cannot export multiple files from index.js
I am creating a styled-components with Atomic Design and I want to separate styled files into one folder and have one index.js to export all files.我正在使用 Atomic Design 创建一个样式组件,我想将样式文件分离到一个文件夹中,并有一个 index.js 来导出所有文件。 I have found that can be done like this way: Splitting Styled-Components into multiple files but export them as one file but In my case when I want to export file inside index.js
我发现可以这样完成:将样式组件拆分为多个文件,但将它们导出为一个文件,但在我的情况下,当我想在index.js
导出文件时
export StyledClosestMeet from 'styledComponents/StyledClosestMeet.js';
I have error我有错误
Declaration or statement expected.ts(1128)声明或声明 expected.ts(1128)
Inside styledComponents folder I have second file:在 styledComponents 文件夹中,我有第二个文件:
import styled from 'styled-components';
import variables from 'settings/variables';
const StyledClosestMeet = styled.div`
color: ${variables.colorMain};
font-size: 2rem;
font-weight: bold;
text-transform: uppercase;
`;
And later I want to import that file inside Atom file:后来我想在 Atom 文件中导入该文件:
import React from 'react';
import {StyledClosestMeet} from 'styledComponents/StyledClosestMeet';
const ClosestMeet = () => {
return <StyledClosestMeet>Najbliższe spotkanie</StyledClosestMeet>;
};
export default ClosestMeet;
I am using jsconfig "baseUrl": "./src"我正在使用 jsconfig "baseUrl": "./src"
You can create an index.js file to export both files like this:您可以创建一个 index.js 文件来导出这两个文件,如下所示:
export { default as Styled1 } from "./styled1";
export { default as Styled2 } from "./styled2";
and then import them like this:然后像这样导入它们:
import { Styled1, Styled2 } from "./styled/index";
You've to export StyledClosestMeet你必须导出 StyledClosestMeet
import styled from 'styled-components';
import variables from 'settings/variables';
const StyledClosestMeet = styled.div`
color: ${variables.colorMain};
font-size: 2rem;
font-weight: bold;
text-transform: uppercase;
`;
export { StyledClosestMeet }
And you can export StyledClosestMeet like below.您可以像下面这样导出 StyledClosestMeet。
export { StyledClosestMeet } from 'styledComponents/StyledClosestMeet.js';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.