Guest User

Untitled

a guest
Nov 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import React from 'react';
  2. import { Button } from 'antd';
  3.  
  4. // extend interface already defined in antd
  5. interface ButtonProps {
  6. onClick: (event: any) => Promise<any>;
  7. }
  8.  
  9. interface AsyncButtonState {
  10. loading: boolean;
  11. }
  12.  
  13. export class AsyncButton extends React.Component<
  14. ButtonProps,
  15. AsyncButtonState
  16. > {
  17. public state = {
  18. loading: false,
  19. };
  20.  
  21. public render() {
  22. return (
  23. <Button
  24. {...this.props}
  25. onClick={this.handleClick}
  26. loading={this.state.loading}
  27. />
  28. );
  29. }
  30.  
  31. private handleClick = async evt => {
  32. this.setState({ loading: true });
  33. await this.props.onClick(evt);
  34. this.setState({ loading: false });
  35. };
  36. }
  37.  
  38. export default AsyncButton;
Add Comment
Please, Sign In to add comment