gpt4 book ai didi

typescript - 如何从文件中导出样式组件?

转载 作者:行者123 更新时间:2023-12-04 12:44:45 25 4
gpt4 key购买 nike

当我使用以下样式组件时

import styled from 'styled-components';

const CarouselContainer = () => {
return styled.div`
& .slick-prev, .slick-next {
position: absolute;
z-index: 1;
top: 50%;
}
& .slick-prev::before, .slick-next::before {
font-size: 35px;
}
& .slick-prev {
left: 5%;
}
& .slick-next {
right: 5%;
}
& .slick-slide {
height: 371px;
position: relative;
}
& .slick-slide img {
height: 371px;
object-fit: cover;
object-position: 0 0;
}
@media all and (min-width: ${providedProps => providedProps.theme.minWidthMediumDevice}) {
& .slick-slide {
height: unset;
position: unset;
}

& .slick-slide img {
height: unset;
object-fit: unset;
object-position: unset;
}
}

@media all and (min-width: ${providedProps => providedProps.theme.minWidthExtraLargeDevice}) {
& .slick-slide {
height: 557px;
position: relative;
}

& .slick-slide img {
height: 557px;
object-fit: cover;
object-position: 0 0;
}
}
`;
};

export default CarouselContainer;

作为
import CarouselContainer from './CarouselContainer';
...
<CarouselContainer>
...
</CarouselContainer>

我收到错误
JSX element type
'StyledComponentClass<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>,
HTMLDivElement>, any,
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>>' is
not a constructor function for JSX elements. Property 'render' is
missing...

我究竟做错了什么?

最佳答案

另一种选择是将其定义为:

import styled from 'styled-components';

const CarouselContainer = styled.div`
// your styles
`;

const StyledComponent = styled.div`
// your styles
`;

export { CarouselContainer, StyledComponent };
并使用它:
import { CarouselContainer, StyledComponent } from './CarouselContainer';
...
<CarouselContainer>
...
</CarouselContainer>

关于typescript - 如何从文件中导出样式组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52991728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com