在JSON中获取HTML以在React Component中呈现为HTML

时间:2022-08-22 20:24:53

Trying to figure out how can i get the link to actually render as a link. Right now after i read this line of text from my Json file, react renders the hyperlink as literal text, it doesn't render it as a link.

试图找出如何获得实际呈现为链接的链接。现在,当我从我的Json文件中读取这行文本后,react将超链接呈现为文本文本,它不会将其呈现为链接。

someData.json

[{
    "about":   "John has a blog you can read <a href=\"http://www.john.com/blog/\" target=\"_blank\">here</a>."
}]

someComponent.js

const Person = Component({
    store: Store('/companies'),
    render(){
        var company = this.store.value()[this.props.companyId];

        return (
            <div id='ft-interviewee className="all-100"'>
                <p className="section-heading bold padding-top-20 font-22">Person</p>
                <div className="column-group horizontal-gutters">
                    <div className="all-10">
                        <div>{company.people.person.about}</div>
                    </div>

            </div>
        )
    }
});

1 个解决方案

#1


1  

You can use dangerouslySetInnerHTML

您可以使用dangerouslySetInnerHTML

<div dangerouslySetInnerHTML={ { __html: company.people.person.about } }></div>

Example

#1


1  

You can use dangerouslySetInnerHTML

您可以使用dangerouslySetInnerHTML

<div dangerouslySetInnerHTML={ { __html: company.people.person.about } }></div>

Example