Skip to content

Commit 952dddd

Browse files
authored
Merge pull request #119 from arcataroger/fix/examples
Update examples sub-repo
2 parents 4412919 + 5320502 commit 952dddd

10 files changed

Lines changed: 1695 additions & 19081 deletions

File tree

docs/meta-tags.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ renderMetaTags([...data.page.seo, ...data.site.favicon]);
6262

6363
This function generates React `<meta>` and `<link />` elements, so it is compatible with React packages like [`react-helmet`](https://www.npmjs.com/package/react-helmet).
6464

65-
For a complete example take a look at our [examples directory](https://github.com/datocms/react-datocms/tree/master/examples).
66-
6765
```js
6866
import React from 'react';
6967
import { renderMetaTags } from 'react-datocms';
68+
import { Helmet } from 'react-helmet';
7069

7170
function Page({ data }) {
7271
return (
@@ -79,6 +78,28 @@ function Page({ data }) {
7978
}
8079
```
8180

81+
In React 19+, you can also directly use meta tags in JSX without any external libraries: https://react.dev/blog/2024/12/05/react-19#support-for-metadata-tags
82+
83+
```js
84+
import React from 'react';
85+
import { renderMetaTags } from 'react-datocms';
86+
87+
function Page({ data }) {
88+
return (
89+
<div>
90+
{
91+
renderMetaTags([...data.page.seo, ...data.site.favicon])
92+
// returns an array of JSX elements like
93+
// <title/>, <link/>, <meta/>, etc.
94+
}
95+
</div>
96+
);
97+
}
98+
```
99+
100+
For a complete React 19 example, take a look at our [examples directory](https://github.com/datocms/react-datocms/tree/master/examples).
101+
102+
82103
## `renderMetaTagsToString()`
83104

84105
This function generates an HTML string containing `<meta>` and `<link />` tags, so it can be used server-side.

examples/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>DatoCMS Plugin</title>
8+
</head>
9+
10+
<body>
11+
<div id="root"></div>
12+
<script type="module" src="./src/index.jsx"></script>
13+
</body>
14+
15+
</html>

0 commit comments

Comments
 (0)