-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathnameEdit.tsx
More file actions
41 lines (34 loc) · 966 Bytes
/
nameEdit.tsx
File metadata and controls
41 lines (34 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as React from 'react';
interface Props {
initialUserName : string;
onNameUpdated : (newName: string) => void;
changed: boolean;
}
interface State{
editingName: string;
}
export class NameEditComponent extends React.Component<Props, State>{
constructor(props: Props){
super(props);
this.state = {editingName: this.props.initialUserName};
}
onChange = (event) =>{
this.setState({editingName: event.target.value});
}
onNameSubmit = (event: any): any => {
this.props.onNameUpdated(this.state.editingName);
}
public render(){
return(
<>
<label>Update Name:</label>
<input value={this.state.editingName} onChange={this.onChange} />
<button className="btn btn-default" onClick={this.onNameSubmit}>Change</button>
<div>
<span>Changed: </span>
<input type="checkbox" checked={this.props.changed} title="Is it changed?"/>
</div>
</>
);
}
}