- Notifications
You must be signed in to change notification settings - Fork24
React Structured Data provides an easy way to add structured data to your React apps
License
bentaylor2/react-structured-data
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
React Structured Data provides an easy way to add structured data to your React apps. Structured data is a standardized format for providing information about a page and classifying the page content. This library follows guidelines specified athttp://schema.org/.
yarn add react-structured-data
npm install react-structured-data --save
The following JSX:
<JSONLD><Productname="Product Name"><AggregateRatingratingValue={4.3}reviewCount={197}/><GenericCollectiontype="review"><Reviewname="It's awesome"reviewBody="This is Great! My family loves it"datePublished="11/22/1963"><Authorname="Jerry"/><Locationname="Chicago, IL"/><RatingratingValue={5}/></Review><Reviewname="Very cool"reviewBody="I like this a lot. Very cool product"datePublished="11/22/1963"><Authorname="Cool Carl"/><Locationname="Chicago, IL"/><RatingratingValue={4}/></Review></GenericCollection></Product></JSONLD>
will add the following to your markup (will be minified):
<scripttype="application/ld+json">{"@context":"https://schema.org/","@type":"Product","name":"Product Name","aggregateRating":{"@type":"AggregateRating","ratingValue":4.3,"reviewCount":197},"review":[{"@type":"Review","datePublished":"11/22/1963","reviewBody":"This is Great! My family loves it","name":"It's awesome","author":{"@type":"Person","name":"Jerry"},"locationCreated":{"@type":"AdministrativeArea","name":"Chicago, IL"},"reviewRating":{"@type":"Rating","ratingValue":5}},{"@type":"Review","datePublished":"11/22/1963","reviewBody":"I like this a lot. Very cool product","name":"Very cool","author":{"@type":"Person","name":"Cool Carl"},"locationCreated":{"@type":"AdministrativeArea","name":"Chicago, IL"},"reviewRating":{"@type":"Rating","ratingValue":4}}]}</script>
| PropType | Value | Description |
|---|---|---|
| type | String | The @type description in the json-ld body:"@type": "Product" |
| jsonldtype | String | The value of the @type description in the json-ld body:"@type": "Product" |
| schema | Object (json) | This should be the schema that you want for your structured data node:{name: "It is awesome", reviewBody: "This is great!"} |
| PropType | Value | Description |
|---|---|---|
| dangerouslyExposeHtml | Boolean | Set this to render the json within script tag usingdangerouslySetInnerHTML |
| PropType | Value | Description |
|---|---|---|
| parentID | String | Sets the id of the schema that becomes a reference that the children point to"@id": "product-x" |
| id | String | similar to parentID but uses the ID on itself |
There are several preset schema components that can be used
- AggregateRating
- Answer
- Author
- ItemReviewed
- Location
- Product
- Question
- Rating
- Review
If you would like to use a component that is not listed, simply use the Generic component and add the prop jsonldtype.Generic and GenericCollection allow you to add your own structured data type.
For example, If Review preset didn't exist, you could write:
<JSONLD><Generictype="review"jsonldtype="Review"schema={{name:"It is awesome",reviewBody:"This is great!"}}><Generictype="itemReviewed"jsonldtype="Product"schema={{"@id":"product-x"}}/><Generictype="author"jsonldtype="Person"schema={{name:"Cool Carl"}}/><Generictype="locationCreated"jsonldtype="AdministrativeArea"schema={{name:"Chicago, IL"}}/></Generic></JSONLD>
This will output (minified):
<scripttype="application/ld+json">{"@context":"http://schema.org/","@type":"Review","name":"It is awesome","reviewBody":"This is great!","itemReviewed":{"@type":"Product","@id":"product-x"},"author":{"@type":"Person","name":"Cool Carl"},"locationCreated":{"@type":"AdministrativeArea","name":"Chicago, IL"}}</script>
This may seem not as ideal as using the presets, but this allows completely customizable structured data.There will also be more preset components to come in future releases to make implementation easier so stay tuned!
For more information on Structured data, visithttps://developers.google.com/search/docs/guides/intro-structured-data, and alsohttp://schema.org/.You can also validate the structured data here:https://search.google.com/structured-data/testing-tool.
TBA
MIT License
About
React Structured Data provides an easy way to add structured data to your React apps
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.