Call Multiple Functions From An onClick Event Handler In React

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] okay so in this video we're just gonna go over how you can call multiple functions within an onclick handler so all I have here is a react app it's blank basically I have a little mark up here then I have two functions number one number two we're just going to use those to demonstrate and then over here just my app is open and I have a console open here so I'm going to show you how to do this in two ways the first is going to be in line and then secondly we'll bring it out into its own function where we call both of these so first of all we're going to need an on-click so let's add that here and that's gonna be equal to open up some brackets now normally if you just have a single on click function that you want to call you just would place it in here but we can't quite do that so we're gonna go like this and we're going to create a function here and we're gonna open up some brackets and then we'd all we do is we go number what so number one so we call that and then we can go down and we can say number two and we save that or reformat for us and now we can come over to here now let's just clear this out so you can see a little bit better and if we call both these calling the first function which is what our console dot log is and calling second function which is our second one so that's how you would do it in line now if we wanted to kind of track that out into its own thing we can go like this and create a new function here can you function and call it will say call both and all that's gonna do is call number number one and number two and then we can just go ahead and call that here so we're gonna get rid of all this and we are going to call that in here so call both and no we're not calling that so don't put any brackets on that and again let's see this in action we'll close up for you and if we go ahead and we push the button we're gonna get both of those so hopefully that's a little bit helpful I've had to look that up before a few times so hopefully it can help you out if you like the video go ahead and subscribe or hit like until next one thanks for watching
Info
Channel: Darwin Tech
Views: 28,257
Rating: undefined out of 5
Keywords: react js tutorial for beginners, reactjs, react, javascript tutorial for beginners, javascript tutorial, onclick javascript, onclick event in javascript, event handlers in javascript
Id: 8YsvA0r3rI0
Channel Id: undefined
Length: 2min 41sec (161 seconds)
Published: Sat Apr 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.