Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit ac1f634

Browse files
justingreenbergmxstbr
authored andcommitted
chore(core|templates): Use React.Children to manage opaque prop data (#815)
* chore(core): Use React.Children helpers for opaque props * fix(Button): small nit, tidy Button code * chore(internals): Update app template
1 parent bfe0c20 commit ac1f634

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

app/components/Button/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* otherwise it'll render a link with an onclick
77
*/
88

9-
import React, { PropTypes } from 'react';
9+
import React, { PropTypes, Children } from 'react';
1010

1111
import styles from './styles.css';
1212

@@ -15,13 +15,17 @@ function Button(props) {
1515

1616
// Render an anchor tag
1717
let button = (
18-
<a className={className} href={props.href} onClick={props.onClick}>{props.children}</a>
18+
<a className={className} href={props.href} onClick={props.onClick}>
19+
{Children.toArray(props.children)}
20+
</a>
1921
);
2022

2123
// If the Button has a handleRoute prop, we want to render a button
2224
if (props.handleRoute) {
2325
button = (
24-
<button className={className} onClick={props.handleRoute} >{props.children}</button>
26+
<button className={className} onClick={props.handleRoute}>
27+
{Children.toArray(props.children)}
28+
</button>
2529
);
2630
}
2731

app/containers/App/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function App(props) {
3232
<A className={styles.logoWrapper} href="https://twitter.com/mxstbr">
3333
<Img className={styles.logo} src={Banner} alt="react-boilerplate - Logo" />
3434
</A>
35-
{props.children}
35+
{React.Children.toArray(props.children)}
3636
<Footer />
3737
</div>
3838
);

app/containers/LanguageProvider/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class LanguageProvider extends React.Component { // eslint-disable-line r
1616
render() {
1717
return (
1818
<IntlProvider locale={this.props.locale} messages={this.props.messages[this.props.locale]}>
19-
{this.props.children}
19+
{React.Children.only(this.props.children)}
2020
</IntlProvider>
2121
);
2222
}

docs/testing/component-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Button(props) {
2929
return (
3030
<button className="btn" onClick={props.onClick}>
3131
<CheckmarkIcon />
32-
{ props.children }
32+
{ React.children.only(props.children) }
3333
</button>
3434
);
3535
}

internals/templates/appContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class App extends React.Component { // eslint-disable-line react/
2424
render() {
2525
return (
2626
<div className={styles.container}>
27-
{this.props.children}
27+
{React.children.toArray(this.props.children)}
2828
</div>
2929
);
3030
}

internals/templates/languageProvider/languageProvider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class LanguageProvider extends React.Component { // eslint-disable-line r
1616
render() {
1717
return (
1818
<IntlProvider locale={this.props.locale} messages={this.props.messages[this.props.locale]}>
19-
{this.props.children}
19+
{React.children.only(this.props.children)}
2020
</IntlProvider>
2121
);
2222
}

0 commit comments

Comments
 (0)