Show notes
Hey there friends so I've been doing some live streaming through discord a
live stream at actually I'm on zoom and then I live stream it to YouTubeand then we chat on Discord. It's a fun time if you haven't joined us thenyou should because it's a good time.So anyway yesterday I was live streaming and I made a discovery thanks to
some of the folks who were hanging out with us in the live stream. So whenyou respond to a change event or on submit event for a form or somethingwe're talking about react here or just vanilla JavaScript Dom APIs whenyouYour event handler that gets called is going to get called with an eventobject and that object is going to have a target and it's also going tohave a current target.Well, I always thought that Target is pretty much what you want all the
time and I just realized because I was moving some stuff over to TypeScriptand that's what I've been live streaming is moving my epic react workshopsto TypeScript. And I realized that when you do event.Target withTypeScript, it says, hey, I realized that this event is on an HTML inputelement.But I don't know what event.Target is going to be so you're going to have
to do some sort of casting or something like that. And that always botheredme for a long time. Well during the live stream somebody mentioned that Icould use current target instead and that would always be the input elementand and so I tried it and of course it worked and and then it it dawned onme the implications of how these things work and and using TypeScript ingeneral and so now I pretty much just use current target pretty much allthe time.So I've switched from default to target and use current target when I need
to I've,Switched that now I default to current target So let me justdescribe that really quick A target is the element that triggered theevent. So let's say you have a button and inside of that button you have aspan that says like a side one and then another span that says side two andthen you click on the side one.Target is going to be the span inside of the button, but if you put the
event handler on the button itself and then current target is going to bethe button itself. So the current target is going to be where the event wasbound and target is going to be where the event happened.Well most of the time in react you're going to like that value is going to
be the same either way like especially when we're talking about inputs andand buttons and stuff most of the time what you really want is the buttonitself or or the input is what we're typically looking for or the form.And so only if you're doing like your own version of event delegation, do
you want to use target? So that's something that I learned yesterday kindof interesting. Use event dot current target instead of event dot target bydefault. Hope that's helpful. Have an awesome day. We'll chat with youlater.
