[英]How can i pass a pirce of HTML content into a stateless react component?
I want to make a simple React component that wraps the given HTML content into a tag that serves as a context in which the content is displayed. 我想制作一个简单的React组件,将给定的HTML内容包装到一个标签中,该标签用作显示内容的上下文。
function Content(content) {
return <div>{content}</div>;
}
<Content>
<span>Hey!</span>
</Content>
What am i doing wrong? 我究竟做错了什么?
function Content(props) {
return <div>{props.children}</div>;
}
Using ES6 syntax: 使用ES6语法:
const Content = ({ children }) => <div>{children}</div>
Simple React component that wraps the given HTML content. 包装了给定HTML内容的简单React组件。
var content = "<Content><span>Hey!</span></Content>"
function Content() {
return (
<div className="content" dangerouslySetInnerHTML={{__html:
content}}>
</div>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.