Reactjs 基于prop的动态样式化组件标签
我正在尝试创建一个带有样式化组件的动态标记。标签通过道具接收 以下是代码示例:Reactjs 基于prop的动态样式化组件标签,reactjs,typescript,styled-components,Reactjs,Typescript,Styled Components,我正在尝试创建一个带有样式化组件的动态标记。标签通过道具接收 以下是代码示例: import * as React from 'react'; import styled from 'styled-components'; type ContainerProps = { children: React.ReactNode, type?: 'section' | 'div' | 'article', } const Container = styled.div` color
import * as React from 'react';
import styled from 'styled-components';
type ContainerProps = {
children: React.ReactNode,
type?: 'section' | 'div' | 'article',
}
const Container = styled.div`
color: ${props => props.theme.primaryColor};
`;
const Icon = styled.div<ContainerProps>`
background-color: red;
`;
const container: React.FunctionComponent<ContainerProps['children']> = ({ children, type = 'section' }: ContainerProps) => {
return (
<Container>
<{ children }
</Container>
);
};
export default container;
import*as React from'React';
从“样式化组件”导入样式化;
类型ContainerProps={
子项:React.React节点,
类型?:“section”|“div”|“article”,
}
const Container=styled.div`
颜色:${props=>props.theme.primaryColor};
`;
const Icon=styled.div`
背景色:红色;
`;
const container:React.FunctionComponent=({children,type='section'}:ContainerProps)=>{
返回(
您可以使用,如下所示:
import*as React from'React';
从“样式化组件”导入样式化;
类型ContainerProps={
子项:React.React节点,
类型?:“section”|“div”|“article”,
}
const Container=styled.div`
颜色:${props=>props.theme.primaryColor};
`;
const Icon=styled.div`
背景色:红色;
`;
const container:React.FunctionComponent=({children,type='section'}:ContainerProps)=>{
返回(
{儿童}
);
};
导出默认容器;
请看我根据您的代码拼凑的这个您可以使用,如下所示:
import*as React from'React';
从“样式化组件”导入样式化;
类型ContainerProps={
子项:React.React节点,
类型?:“section”|“div”|“article”,
}
const Container=styled.div`
颜色:${props=>props.theme.primaryColor};
`;
const Icon=styled.div`
背景色:红色;
`;
const container:React.FunctionComponent=({children,type='section'}:ContainerProps)=>{
返回(
{儿童}
);
};
导出默认容器;
看到我根据你的代码拼凑的这个了吗