Guest User

Untitled

a guest
Jun 6th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. interface State {
  2. username: string;
  3. password: string;
  4. }
  5.  
  6. class LoginForm extends React.Component<Props, State> {
  7. readonly state: Readonly<State> = {
  8. username: '',
  9. password: ''
  10. }
  11.  
  12. onChange = (key: keyof State) => (e: React.FormEvent<HTMLInputElement>) => {
  13. const value = e.currentTarget.value;
  14. this.setState({ [key]: value }); // error
  15. }
  16.  
  17. render() {
  18. return (
  19. ...
  20. <TextField
  21. ...
  22. onChange={this.onChange('username')}
  23. />
  24. <TextField
  25. ...
  26. onChange={this.onChange('password')}
  27. />
  28. ...
  29. )
  30. }
  31. }
  32.  
  33. onChange = (key: 'username' | 'password') => ...
Add Comment
Please, Sign In to add comment