Skip to content

Commit

Permalink
chore(core|templates): Use React.Children to manage opaque prop data (r…
Browse files Browse the repository at this point in the history
…eact-boilerplate#815)

* chore(core): Use React.Children helpers for opaque props

* fix(Button): small nit, tidy Button code

* chore(internals): Update app template
  • Loading branch information
justingreenberg authored and mxstbr committed Aug 2, 2016
1 parent bfe0c20 commit ac1f634
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions app/components/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* otherwise it'll render a link with an onclick
*/

import React, { PropTypes } from 'react';
import React, { PropTypes, Children } from 'react';

import styles from './styles.css';

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

// Render an anchor tag
let button = (
<a className={className} href={props.href} onClick={props.onClick}>{props.children}</a>
<a className={className} href={props.href} onClick={props.onClick}>
{Children.toArray(props.children)}
</a>
);

// If the Button has a handleRoute prop, we want to render a button
if (props.handleRoute) {
button = (
<button className={className} onClick={props.handleRoute} >{props.children}</button>
<button className={className} onClick={props.handleRoute}>
{Children.toArray(props.children)}
</button>
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function App(props) {
<A className={styles.logoWrapper} href="https://twitter.com/mxstbr">
<Img className={styles.logo} src={Banner} alt="react-boilerplate - Logo" />
</A>
{props.children}
{React.Children.toArray(props.children)}
<Footer />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion app/containers/LanguageProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class LanguageProvider extends React.Component { // eslint-disable-line r
render() {
return (
<IntlProvider locale={this.props.locale} messages={this.props.messages[this.props.locale]}>
{this.props.children}
{React.Children.only(this.props.children)}
</IntlProvider>
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/testing/component-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Button(props) {
return (
<button className="btn" onClick={props.onClick}>
<CheckmarkIcon />
{ props.children }
{ React.children.only(props.children) }
</button>
);
}
Expand Down
2 changes: 1 addition & 1 deletion internals/templates/appContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class App extends React.Component { // eslint-disable-line react/
render() {
return (
<div className={styles.container}>
{this.props.children}
{React.children.toArray(this.props.children)}
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion internals/templates/languageProvider/languageProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class LanguageProvider extends React.Component { // eslint-disable-line r
render() {
return (
<IntlProvider locale={this.props.locale} messages={this.props.messages[this.props.locale]}>
{this.props.children}
{React.children.only(this.props.children)}
</IntlProvider>
);
}
Expand Down

0 comments on commit ac1f634

Please sign in to comment.