Gathering detailed insights and metrics for react-doc-meta
Gathering detailed insights and metrics for react-doc-meta
Gathering detailed insights and metrics for react-doc-meta
Gathering detailed insights and metrics for react-doc-meta
npm install react-doc-meta
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
59 Stars
15 Commits
10 Forks
4 Watchers
1 Branches
3 Contributors
Updated on Jun 09, 2024
Latest Version
0.2.0
Package Id
react-doc-meta@0.2.0
Size
3.65 kB
NPM Version
2.7.4
Node Version
0.12.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Render meta tags on the server & client for ReactJS. You can render meta tags with any kind of attributes / properties.
Built with React Side Effect.
====================
npm install --save react-doc-meta
Dependencies: React >= 0.12.0
1var App = React.createClass({ 2 render: function () { 3 var tags = [ 4 {name: "description", content: "lorem ipsum dolor"}, 5 {itemProp: "name", content: "The Name or Title Here"}, 6 {itemProp: "description", content: "This is the page description"}, 7 {itemProp: "image", content: "http://www.example.com/image.jpg"}, 8 {name: "twitter:card", content: "product"}, 9 {name: "twitter:site", content: "@publisher_handle"}, 10 {name: "twitter:title", content: "Page Title"}, 11 {name: "twitter:description", content: "Page description less than 200 characters"}, 12 {name: "twitter:creator", content: "@author_handle"}, 13 {name: "twitter:image", content: "http://www.example.com/image.html"}, 14 {name: "twitter:data1", content: "$3"}, 15 {name: "twitter:label1", content: "Price"}, 16 {name: "twitter:data2", content: "Black"}, 17 {name: "twitter:label2", content: "Color"}, 18 {property: "og:title", content: "Title Here"}, 19 {property: "og:type", content: "article"}, 20 {property: "og:url", content: "http://www.example.com/"}, 21 {property: "og:image", content: "http://example.com/image.jpg"}, 22 {property: "og:description", content: "Description Here"}, 23 {property: "og:site_name", content: "Site Name, i.e. Moz"}, 24 {property: "og:price:amount", content: "15.00"}, 25 {property: "og:price:currency", content: "USD"}, 26 {weirdfield: "something", content: "really really cool", hello:"world", meh: "hahaha"} 27 ] 28 29 // DocMeta will construct meta tags with properties & values mirroring the above key-value pairs 30 return ( 31 <DocMeta tags={tags}> 32 <this.props.activeRouteHandler /> 33 </DocMeta> 34 ); 35 } 36});
On the browser the above will produce:
<meta name="description" content="lorem ipsum dolor" data-doc-meta="true">
<meta itemprop="name" content="The Name or Title Here" data-doc-meta="true">
<meta itemprop="description" content="This is the page description" data-doc-meta="true">
<meta itemprop="image" content="http://www.example.com/image.jpg" data-doc-meta="true">
<meta name="twitter:card" content="product" data-doc-meta="true">
<meta name="twitter:site" content="@publisher_handle" data-doc-meta="true">
<meta name="twitter:title" content="Page Title" data-doc-meta="true">
<meta name="twitter:description" content="Page description less than 200 characters" data-doc-meta="true">
<meta name="twitter:creator" content="@author_handle" data-doc-meta="true">
<meta name="twitter:image" content="http://www.example.com/image.html" data-doc-meta="true">
<meta name="twitter:data1" content="$3" data-doc-meta="true">
<meta name="twitter:label1" content="Price" data-doc-meta="true">
<meta name="twitter:data2" content="Black" data-doc-meta="true">
<meta name="twitter:label2" content="Color" data-doc-meta="true">
<meta property="og:title" content="Title Here" data-doc-meta="true">
<meta property="og:type" content="article" data-doc-meta="true">
<meta property="og:url" content="http://www.example.com/" data-doc-meta="true">
<meta property="og:image" content="http://example.com/image.jpg" data-doc-meta="true">
<meta property="og:description" content="Description Here" data-doc-meta="true">
<meta property="og:site_name" content="Site Name, i.e. Moz" data-doc-meta="true">
<meta property="og:price:amount" content="15.00" data-doc-meta="true">
<meta property="og:price:currency" content="USD" data-doc-meta="true">
<meta weirdfield="something" content="really really cool" hello="world" meh="hahaha" data-doc-meta="true">
Works for nested components too!
Also, you don't need to wrap components with <DocMeta tags={tags}>...</DocMeta>
, writing <DocMeta tags={tags} />
should work just fine.
1 2class JoinPage extends Component { 3 static propTypes = { 4 status: PropTypes.string, 5 user: PropTypes.object 6 } 7 8 render() { 9 var tags = [ 10 {name: "description", content: "test"} 11 ] 12 13 // only this meta should render in the DOM 14 var tags2 = [ 15 {name: "description", content: "test 2"} 16 ] 17 18 return ( 19 <div> 20 <DocMeta tags={tags} /> 21 <DocMeta tags={tags2} /> 22 <JoinForm {...this.props} /> 23 </div> 24 ); 25 } 26} 27 28class JoinForm extends Component { 29 30 constructor(props) { 31 super(props); 32 this.state = { 33 }; 34 } 35 36 render(){ 37 var tags = [ 38 {name: "description", content: "a nested doc meta"} 39 ] 40 41 42 return ( 43 <div> 44 <DocMeta tags={tags} /> 45 <p>Join</p> 46 <NavLink routeName="account">Test</NavLink> 47 </div> 48 ) 49 } 50} 51
On the browser the above will produce
<meta name="description" content="a nested doc meta" data-doc-meta="true">
If you use it on server, call DocMeta.rewind()
after rendering components to string to retrieve the array of meta tags given to the innermost DocMeta
. You can then embed this meta tags into HTML page template like this using es6 spread props:
1 2 //... the rest of the html-document.jsx... 3 4 render() { 5 const { state, markup, script, css, lang } = this.props; 6 let metaTags = DocMeta.rewind(); 7 8 return ( 9 <html > 10 <head> 11 { 12 metaTags.map((tag, index) => 13 <meta data-doc-meta="true" key={index} {...tag} />) 14 } 15 </head> 16 17 <body> 18 <div id="root" dangerouslySetInnerHTML={{__html: markup}} /> 19 20 <script dangerouslySetInnerHTML={{__html: state}} /> 21 </body> 22 </html> 23 ); 24 } 25
Because this component keeps track of mounted instances, you have to make sure to call rewind
on server, or you'll get a memory leak.
TEST!
Contributions welcomed! Raise issues / submit pull requests thank you!
0.1.0 Adapted solution for react-document-title for meta tags
0.1.1 Removed undeclared underscore dependency. Using native array prototype functions instead.
0.2.0 Merged a critical fix that causes memory leaks on _serverMeta
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/10 approved changesets -- score normalized to 3
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More