Last active
November 7, 2016 18:04
-
-
Save kof/2ce5f31ca85257e5a6441c352f1ce697 to your computer and use it in GitHub Desktop.
When to use functional components.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Title = ({children}) => ( | |
<div className={classes.titleContainer}> | |
<span className={classes.titleIcon} /> | |
<h3 className={classes.titleHeadline}> | |
{children} | |
</h3> | |
</div> | |
) | |
const Select = ({value, options, onChange}) => ( | |
<select onChange={onChange} value={value} className={classes.select}> | |
{options.map(option => ( | |
<option value={option.value}>{option.title}</option> | |
))} | |
</select> | |
) | |
const Footer = ({onClose}) => ( | |
<div className={classes.footer}> | |
<div className={classes.hint}> | |
Some text. | |
</div> | |
<button className={classes.done} onClick={onClose}>Done</button> | |
</div> | |
) | |
export default class MyComponent extends PureComponent { | |
onChange = (e) => { | |
// Handle select change. | |
} | |
onClose = (e) => { | |
// Handle close. | |
} | |
render() { | |
return ( | |
<div className={classes.root}> | |
<Title>Some Title</Title> | |
<Select onChange={this.onChange} /> | |
<Footer onClose={this.onClose} /> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment