我有一个服务器响应,其中包含一个作为prop传递给反应组件的html字符串。在html中有代码需要用React组件代替。如何将字符串与JSX结合使用
我已经使用react-string-replace来获得这个工作,但它似乎不能与HTML一起工作,因为标签被React转义。有谁知道这可能会如何解决?
import React from 'react';
import replace from 'react-string-replace';
const reg = /\{(name)\}/g;
const Name = props => {
return (
Hello {props.name}
)
}
class Embed extends React.Component {
render() {
const person = this.props.person
const component = ;
const output = replace(
this.props.content,
reg,
prop => component
);
return (
{output}
)
}
}
const Greeting = props => {
return ;
};
export default Greeting;
2017-02-15
Adam