Skip to content

Commit 4e48b6b

Browse files
committed
[changed] Pass named children as props
Fixes #1968
1 parent 3bfab02 commit 4e48b6b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

examples/sidebar/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ class IndexSidebar extends React.Component {
9292

9393
class App extends React.Component {
9494
render() {
95-
const { children } = this.props
95+
const { content, sidebar } = this.props
9696

9797
return (
9898
<div>
9999
<div className="Sidebar">
100-
{children ? children.sidebar : <IndexSidebar />}
100+
{sidebar || <IndexSidebar />}
101101
</div>
102102
<div className="Content">
103-
{children ? children.content : <Index />}
103+
{content || <Index />}
104104
</div>
105105
</div>
106106
)

modules/RoutingContext.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import invariant from 'invariant'
22
import React, { Component } from 'react'
3+
import { isReactChildren } from './RouteUtils'
34
import getRouteParams from './getRouteParams'
45

56
const { array, func, object } = React.PropTypes
@@ -46,7 +47,7 @@ class RoutingContext extends Component {
4647
if (components) {
4748
element = components.reduceRight((element, components, index) => {
4849
if (components == null)
49-
return element // Don't create new children use the grandchildren.
50+
return element // Don't create new children; use the grandchildren.
5051

5152
const route = routes[index]
5253
const routeParams = getRouteParams(route, params)
@@ -59,13 +60,18 @@ class RoutingContext extends Component {
5960
routes
6061
}
6162

62-
if (element)
63+
if (isReactChildren(element)) {
6364
props.children = element
65+
} else if (element) {
66+
for (let prop in element)
67+
if (element.hasOwnProperty(prop))
68+
props[prop] = element[prop]
69+
}
6470

6571
if (typeof components === 'object') {
6672
const elements = {}
6773

68-
for (const key in components)
74+
for (let key in components)
6975
if (components.hasOwnProperty(key))
7076
elements[key] = this.createElement(components[key], props)
7177

0 commit comments

Comments
 (0)