Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface State {
- username: string;
- password: string;
- }
- class LoginForm extends React.Component<Props, State> {
- readonly state: Readonly<State> = {
- username: '',
- password: ''
- }
- onChange = (key: keyof State) => (e: React.FormEvent<HTMLInputElement>) => {
- const value = e.currentTarget.value;
- this.setState({ [key]: value }); // error
- }
- render() {
- return (
- ...
- <TextField
- ...
- onChange={this.onChange('username')}
- />
- <TextField
- ...
- onChange={this.onChange('password')}
- />
- ...
- )
- }
- }
- onChange = (key: 'username' | 'password') => ...
Add Comment
Please, Sign In to add comment