Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 基于prop的动态样式化组件标签_Reactjs_Typescript_Styled Components - Fatal编程技术网

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)=>{
返回(
{儿童}
);
};
导出默认容器;
看到我根据你的代码拼凑的这个了吗