forked from staylor/react-helmet-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProvider.js
45 lines (34 loc) · 1018 Bytes
/
Provider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import HelmetData from './HelmetData';
const defaultValue = {};
export const Context = React.createContext(defaultValue);
export const providerShape = PropTypes.shape({
setHelmet: PropTypes.func,
helmetInstances: PropTypes.shape({
get: PropTypes.func,
add: PropTypes.func,
remove: PropTypes.func,
}),
});
const canUseDOM = typeof document !== 'undefined';
export default class Provider extends Component {
static canUseDOM = canUseDOM;
static propTypes = {
context: PropTypes.shape({
helmet: PropTypes.shape(),
}),
children: PropTypes.node.isRequired,
};
static defaultProps = {
context: {},
};
static displayName = 'HelmetProvider';
constructor(props) {
super(props);
this.helmetData = new HelmetData(this.props.context, Provider.canUseDOM);
}
render() {
return <Context.Provider value={this.helmetData.value}>{this.props.children}</Context.Provider>;
}
}