Skip to content

Instantly share code, notes, and snippets.

@tortillaj
Last active January 18, 2018 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tortillaj/8b24159547cea434c398ddcd05e46ad0 to your computer and use it in GitHub Desktop.
Save tortillaj/8b24159547cea434c398ddcd05e46ad0 to your computer and use it in GitHub Desktop.
React Recompose blog post
export default class Button extends React.Component {
constructor(props) {
super(props)
this.state = {
isLoading: false,
}
}
static propTypes = {
onClick: PropTypes.func,
className: PropTypes.string,
type: PropTypes.string,
children: PropTypes.any.isRequired,
}
static defaultProps = {
type: 'button',
}
doSomething = (e) => {
if (!this.props.onClick) return
this.setState({ isLoading: true })
this.props.onClick(e).then(() => this.setState({ isLoading: false ]))
}
render() {
const { type, className, children ) = this.props
return (
<button type={type} className={className} onClick={this.doSomething}>
{this.state.isLoading && <Loading />}
{!this.state.isLoading && children}
</button>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment