[英]How can I get children source code in React?
Is react have a possibility to get children prop source code? react 有没有可能得到 children 的 prop 源码?
For example I have component with some kind of code...例如,我有带有某种代码的组件...
<SomeComp>
<Heading>I need this code with Heading tag</Heading>
</SomeComp>
How I can get children as a string?我怎样才能让孩子们成为一个字符串?
I need something like this...我需要这样的东西...
const SomeComp = ({ children }) => {
const highlightedCode = highlight(CHILDREN_TO_SOURCE_STRING_FUNCTION(children))
return (
<>
<div>{highlightedCode}</div>
<div>{children}</div>
</>
)
}
Thx for help谢谢帮助
Not sure what really you're trying to achieve here but this is what you can do.不确定您真正想要在这里实现什么,但这是您可以做的。
<SomeComp>
{`<Heading>I need this code with Heading tag</Heading>`}
</SomeComp>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.