Skip to content

Commit 20bfd8d

Browse files
committed
Merge pull request DefinitelyTyped#8621 from evanbb/master
Adding typings for react-helmet
2 parents 94d8792 + 59c05d5 commit 20bfd8d

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

react-helmet/react-helmet-tests.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/// <reference path="react-helmet.d.ts" />
2+
/// <reference path="../react/react.d.ts" />
3+
4+
import * as React from 'react';
5+
import Helmet from 'react-helmet';
6+
7+
<Helmet title="My Title" />
8+
9+
const head = Helmet.rewind();
10+
const html = `
11+
<!doctype html>
12+
<html>
13+
<head>
14+
${ head.title.toString() }
15+
${ head.meta.toString() }
16+
${ head.link.toString() }
17+
</head>
18+
<body>
19+
<div id="content">
20+
// React stuff here
21+
</div>
22+
</body>
23+
</html>
24+
`;
25+
26+
function HTML() {
27+
return (
28+
<html>
29+
<head>
30+
{ head.title.toComponent() }
31+
{ head.meta.toComponent() }
32+
{ head.link.toComponent() }
33+
</head>
34+
<body>
35+
<div id="content">
36+
// React stuff here
37+
</div>
38+
</body>
39+
</html>
40+
);
41+
}

react-helmet/react-helmet.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Type definitions for react-helmet
2+
// Project: https://github.com/nfl/react-helmet
3+
// Definitions by: Evan Bremer <https://github.com/evanbb>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
/// <reference path="../react/react.d.ts" />
7+
8+
declare module 'react-helmet' {
9+
import { Component } from 'react';
10+
11+
interface HelmetProps {
12+
title?: string;
13+
titleTemplate?: string;
14+
base?: any;
15+
link?: Array<any>;
16+
meta?: Array<any>;
17+
script?: Array<any>;
18+
onChangeClientState?: (newState: any) => void;
19+
}
20+
21+
interface HelmetData {
22+
title: HelmetDatum;
23+
base: HelmetDatum;
24+
link: HelmetDatum;
25+
meta: HelmetDatum;
26+
script: HelmetDatum;
27+
}
28+
29+
interface HelmetDatum {
30+
toString(): string;
31+
toComponent(): Component<any, any>;
32+
}
33+
34+
class Helmet extends Component<HelmetProps, any> {
35+
static rewind(): HelmetData
36+
}
37+
38+
export default Helmet;
39+
}

0 commit comments

Comments
 (0)