Reactjs 如何将`as`用于`styled()包装的react组件`

Reactjs 如何将`as`用于`styled()包装的react组件`,reactjs,styled-components,Reactjs,Styled Components,我想使用as属性更改react组件的标记类型。它看起来不起作用,内容将消失 我想在下面的代码中显示foo文本。 但是,只存在没有值的标记 constchildcomponent=()=>foo; 常量StyledChildComponent=styled(ChildComponent)` //一些风格 `; 常量ParentComponent=()=>( ); Chrome开发工具上没有错误消息 相关模块的版本如下所示 "react": "^16.8.6", "react-dom": "^16

我想使用
as
属性更改react组件的标记类型。它看起来不起作用,内容将消失

我想在下面的代码中显示
foo
文本。 但是,只存在没有值的标记

constchildcomponent=()=>foo;
常量StyledChildComponent=styled(ChildComponent)`
//一些风格
`;
常量ParentComponent=()=>(
);
Chrome开发工具上没有错误消息

相关模块的版本如下所示

"react": "^16.8.6",
"react-dom": "^16.8.6",
"styled-components": "^4.2.0",

如果您想显示
foo
,那么它应该是
foo
,它只是一个示例。实际上
ChildComponent
更复杂,我想把它作为另一个组件。您知道可以这样做吗?因为您正在包装
ChildComponent
,所以您应该将
转发为
。读这里