react-schemaorg is a library designed to simplify the integration of structured data into React applications using Schema.org JSON-LD. It leverages the `schema-dts` package for robust TypeScript definitions, ensuring strong type safety when defining rich snippets, which helps prevent common errors in structured data implementation. The current stable version is 2.0.1, with releases typically addressing dependency updates, minor feature enhancements like `@graph` key support, or improved compatibility with popular head management libraries such as Next.js `next/head` and `react-helmet`. Key differentiators include its strong emphasis on type-checking through `schema-dts`, the provision of both a declarative `<JsonLd>` component and utility functions (`jsonLdScriptProps`, `helmetJsonLdProp`) for flexible integration, and its focus on secure JSON-LD parsing to mitigate potential XSS vulnerabilities.
npm install react-schemaorgVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to embed Schema.org JSON-LD data into a React component using the `<JsonLd>` component from `react-schemaorg`. It defines a `Person` schema for 'Grace Hopper' with various properties, showcasing type-safe data structuring for search engines and other semantic web consumers, leveraging TypeScript definitions from `schema-dts`.
Upgrade your Node.js environment to version 12.0.0 or higher. Ensure your project's build configuration (e.g., `tsconfig.json` `target`) is set to ES2019 or later.
No code fix is generally required for `react-schemaorg` itself. However, ensure that any tools or services consuming the JSON-LD from your application are capable of correctly parsing HTML-escaped content within `<script type="application/ld+json">` tags.
Review your project's build pipeline (e.g., Babel, Webpack configurations) if you experience unexpected behavior or build output differences. Most projects should benefit from this change without explicit modification.
Consult the `schema-dts` type definitions or the official Schema.org documentation to ensure all properties and their types within your JSON-LD object precisely match the expected schema. Use only valid properties for the given `@type`.
Verify that `import { JsonLd } from 'react-schemaorg';` is correctly used at the top of your file. Ensure your build system (e.g., Webpack, Rollup, Babel) is configured to handle ES module imports for React components.Check the documentation for your specific `react-helmet` library version. If `script` is not working, try passing the `helmetJsonLdProp` output to the `scriptElements` prop: `<Helmet scriptElements={[helmetJsonLdProp(...)]} />`.