.html
I'm at the end of this tutorial and I'm just not understanding how e.target.value works. Walk through the end of this tutorial and see the sample code that there is please. I'm newbie both to React and Javascript.
https://facebook.github.io/react/docs/thinking-in-react.html
I'm at the end of this tutorial and I'm just not understanding how e.target.value works. Walk through the end of this tutorial and see the sample code that there is please. I'm newbie both to React and Javascript.
Share Improve this question edited Aug 10, 2017 at 23:51 halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Aug 10, 2017 at 23:19 Diogo MatiasDiogo Matias 2131 gold badge2 silver badges7 bronze badges 4 |3 Answers
Reset to default 14The e
is the argument of an event handler you attach to a certain event on a certain component... in this case the onFilterTextInput
event. Events are objects with certain properties, and e.target
almost always represents a DOM element.
Thus e.target.value
is the value property of some DOM element, in this case that means the text entered in the search input.
When you need to handle multiple controlled input elements, you can add a name attribute to each element and let the handler function choose what to do based on the value of event.target.name. By React DOC
So, 'e' stands for event and target is the element that triggered the event. I find pretty useful this explanation about the difference between event.target and event.currentTarget at W3Schools
e
is the event, which in this case ischange
,target
is the element that triggered the event, which in this case is theinput
, andvalue
is the value of theinput
element – JJJ Commented Aug 10, 2017 at 23:24