Skip to content

Commit 7216187

Browse files
author
Ben Taylor
committed
Adding prop to render with dangerouslySetInnerHTML
1 parent e0eebd3 commit 7216187

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/core/JSONLD.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ export const JSONLD = props => {
1111
? Object.assign({'@context': 'http://schema.org/'}, {[type]: firstChild})
1212
: Object.assign({'@context': 'http://schema.org/'}, firstChild)
1313
}
14-
return (
15-
<script
16-
type="application/ld+json"
17-
dangerouslySetInnerHTML={{
18-
__html: JSON.stringify(json),
19-
}}
20-
/>
14+
15+
return (props.dangerouslyExposeHtml
16+
? <script type="application/ld+json" dangerouslySetInnerHTML={{__html: JSON.stringify(json)}} />
17+
: <script type="application/ld+json">{ JSON.stringify(json) }</script>
2118
);
2219
}
2320

2421
JSONLD.propTypes = {
25-
additionalType: PropTypes.object
22+
additionalType: PropTypes.object,
23+
dangerouslyExposeHtml: PropTypes.bool
24+
};
25+
26+
JSONLD.defaultProps = {
27+
dangerouslyExposeHtml: false
2628
};
2729

2830
export default JSONLD;

src/example/containers/Example.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Review,
99
Author,
1010
Location,
11-
Rating
11+
Rating,
12+
Generic
1213
} from 'react-structured-data';
1314

1415

0 commit comments

Comments
 (0)