Skip to content

Commit 2076f61

Browse files
committed
view prop → component prop
Small change to be coherent with what the React community use.
1 parent 719e98a commit 2076f61

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/ElementPortal.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ const ElementPortal = createReactClass({
1010
id: PropTypes.string,
1111
selector: PropTypes.string,
1212
mapDomNodeToProps: PropTypes.func,
13-
// Remove styles and classes from node.
1413
shouldReset: PropTypes.bool,
15-
view: PropTypes.func
14+
component: PropTypes.func
1615
},
1716

1817
componentDidMount() {
@@ -29,18 +28,17 @@ const ElementPortal = createReactClass({
2928
const mapDomNodeToProps = this.props.mapDomNodeToProps || noop;
3029
const nodesBySelector = (this.props.selector && [].slice.call(document.querySelectorAll(this.props.selector))) || [];
3130
const nodes = nodesById.concat(nodesBySelector);
31+
const { component } = this.props;
3232

3333
nodes.forEach(node => {
3434
if (this.props.shouldReset) {
3535
node.className = '';
3636
node.removeAttribute('style');
3737
}
3838

39-
const View = this.props.view;
40-
41-
const children = View ?
42-
<View {...mapDomNodeToProps(node)} /> :
43-
React.Children.only(this.props.children);
39+
const children = component
40+
? React.createElement(component, mapDomNodeToProps(node))
41+
: React.Children.only(this.props.children);
4442

4543
ReactDOM.unstable_renderSubtreeIntoContainer(
4644
this,

src/withElementPortal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const withElementPortal = (Child) => {
1313
selector={selector}
1414
mapDomNodeToProps={mapDomNodeToProps}
1515
shouldReset={shouldReset}
16-
view={ChildWrapper}
16+
component={ChildWrapper}
1717
/>;
1818
};
1919

test/ElementPortal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test('can render to ElementPortal using selector with custom component', t => {
7474
const Greeting = () => (<div>Hello</div>);
7575
render(
7676
<div>
77-
<ElementPortal selector="li.greeting" view={Greeting}/>
77+
<ElementPortal selector="li.greeting" component={Greeting}/>
7878
</div>,
7979
document.getElementById(appId)
8080
);
@@ -102,7 +102,7 @@ test('map dom node to props', t => {
102102
const Greeting = ({ name, isNew }) => (<div>Hello {isNew && 'and welcome '}{name}</div>);
103103
render(
104104
<div>
105-
<ElementPortal selector="li.greeting" view={Greeting} mapDomNodeToProps={mapDomNodeToProps} />
105+
<ElementPortal selector="li.greeting" component={Greeting} mapDomNodeToProps={mapDomNodeToProps} />
106106
</div>,
107107
document.getElementById(appId)
108108
);

0 commit comments

Comments
 (0)