问题描述
假设我在 React 中有一个简单的组件,我不仅想使用该组件本身,还想使用它的代码,因为它在屏幕上显示? 我怎样才能做到这一点?
这就是我正在做的事情
import Anything from ../../'anywhere';
const CustomComponent = () => {
return (
<div>
<Anything />
</div>
)
}
export default CustomComponent;
然后在另一个文件中
import CustomComponent from './custom-component';
return (
<div codeHighlightStr={CustomComponentString}>
<CustomComponent />
</div>
)
我不知道如何从同一个模块中获取CustomComponentString
1楼
Alexey Baguk
0
2019-02-25 09:30:52
您可以通过查询“jsx to string”来使用 ReactDomServer.renderToString 方法或一些 npm 包
2楼
brk
0
2019-02-25 09:35:53
您可以使用<xmp>标签。
render(){
return (<div>
<xmp>
let test='SomeValue';
document.getElementById('someElement').innetHTML = test;
</xmp>
</div>)
}