import * as React from 'react'; import PropsTypes from './types'; interface State { icon: string, spin: boolean, onClick?: Function } export default class Button extends React.Component { public state: State; constructor(props: PropsTypes, {}) { super(props); this.state = { ...props, spin: this.props.spin || false, icon: this.props.icon }; } componentWillReceiveProps(nextProps: any) { if (nextProps.icon !== this.props.icon) { this.setState({ icon: this.props.icon }) } if (nextProps.spin !== this.props.spin) { this.setState({ spin: nextProps.spin }) } } public render(): JSX.Element { const {icon, spin} = this.state; return ( this.props.onClick && this.props.onClick()}> ); } }