- Notifications
You must be signed in to change notification settings - Fork 349
/
Copy path07-HandlingEvents_ts.tsx
73 lines (64 loc) · 1.98 KB
/
07-HandlingEvents_ts.tsx
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
importReact,{Component}from'react';
/**
*🏆
* The goal of this exercise is to get you more familiar with event handling
* in React. Here we would render an input element and add function to handle
* events on that input element
*/
classFancyInputextendsComponent<any,any>{
constructor(props){
super(props);
/**
* 💡 Here we have initialized the state with inputValue
*/
this.state={
inputValue: ''
}
/**
* ✏️
* Need to bind the handleChange function to appropriate `this`
*/
}
/**
* ✏️
* Need to get the value of the input and set it to the state
* 🧭 Get the value of the input from the synthetic event
* You can get the value by using event.target.value.
* 🧭 Set the value to the state `inputValue` by calling `setState`
*/
handleChange(e){
}
render(){
return(
<React.Fragment>
{
/**
* ✏️
* Need to pass the event handler to the input element.
* In this case we need to pass handleChange function to the
* onChange event
*/
}
<input></input>
{
/**
* 💡
* This div will mirror the user input. For this to work though
* you need to add the handleChange event on the input above
* and update the state when the change happens on the input
*/
}
<div>You typed: {this.state.inputValue}</div>
</React.Fragment>
)
}
}
/**
* 🚨 🚨 DO NOT DELETE OR CHANGE THIS.🚨 🚨
* This is how you would use your above component
* The output of this code is displayed on the browser on the left hand side
*/
constUsage=(props)=>{
return<FancyInput/>
}
exportdefaultUsage;