Skip to content

Commit 0550017

Browse files
author
Sergio Daniel Xalambrí
committed
[add] high-order component
1 parent ee5d486 commit 0550017

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/URLProvider.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component, Children, PropTypes } from 'react';
2+
3+
const propTypes = {
4+
urls: PropTypes.object,
5+
children: PropTypes.array,
6+
};
7+
const defaultProps = {
8+
urls: {},
9+
};
10+
const childContextTypes = {
11+
urls: PropTypes.object,
12+
};
13+
14+
/**
15+
* Set URLs object to React application context
16+
* @param {Object} urls URL to set
17+
* @param {Class} children Application component
18+
*/
19+
class UrlProvider extends Component {
20+
getChildContext() {
21+
return {
22+
urls: this.props.urls,
23+
};
24+
}
25+
26+
render() {
27+
return Children.only(this.props.children[0]);
28+
}
29+
}
30+
31+
UrlProvider.propTypes = propTypes;
32+
UrlProvider.defaultProps = defaultProps;
33+
UrlProvider.childContextTypes = childContextTypes;
34+
35+
export default UrlProvider;

0 commit comments

Comments
 (0)