Тёмный

ReactJS Tutorial - 13 - Event Handling 

Codevolution
Подписаться 672 тыс.
Просмотров 666 тыс.
50% 1

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 153   
@arpansatpathi9645
@arpansatpathi9645 4 года назад
For those of you wondering why he used parentheses in the previous video and not here, it was because he was binding the 'this' keyword with the event handler so that he could change the state. If you're still confused just proceed to next video you will get your answer.
@brunagobi7393
@brunagobi7393 3 года назад
thank you, it was exactly what I was wondering
@simple8810
@simple8810 3 года назад
Thanks man I just came here for this doubt, and he also used arrow function there and not here why?
@lorem349
@lorem349 2 года назад
As far as my understanding, it's cuz he used arrow function before that's why he used parantheses
@aryansahoo9298
@aryansahoo9298 14 дней назад
I think best idea is to just make a root function and then inside that call that function...like onClick = { ( )=>{ something you want... }}...
@sreejithpssap543
@sreejithpssap543 4 года назад
Like many already said, "You are a legend". Perhaps the best trainer I have ever come across
@anoopvasudevan
@anoopvasudevan 4 года назад
Man...thanks for these videos. I bought something in Udemy, and now I'm watching your videos after each Udemy chapter to get more clarity on the topic.
@marynungari6524
@marynungari6524 4 года назад
I also bought tutorial on Udemy, but it dint help, I am so grateful for this tutorial.
@akshay__sood
@akshay__sood 4 года назад
Very nice! You explain concepts by taking both functional and class component in account. This is indeed of much help and provides clarity! Most of your viewers wil agree to this.
@mjdtoto615
@mjdtoto615 4 года назад
So informative tutorial, you can easily follow along and understand the core concepts of react like state and props. These are really important to undersand. This guy is legend. thanx.
@m.muzammilbabar4375
@m.muzammilbabar4375 4 года назад
Brother you are next level! I am really really thankful to you for your this help. May God bless you with the best. I am taking your lectures but the problem is that i am not getting relevant examples to practice the stuff you are teaching. It will be so kind of you if you will give me some link or stuff like that so that i could practice the concepts. Thank you so much!!! :)
@viveks2619
@viveks2619 3 года назад
An observation, that the passing event handler as a function will work if you use an arrow function inside the paranthesis.
@Kg.gibson
@Kg.gibson 4 года назад
thank u so much for the better explanation of components ..really before i was confusing the two...
@bhavukmathur2709
@bhavukmathur2709 11 месяцев назад
@Codevolution, Thanks ! One question, why I don't see multiple logs when I click the button multiple times? I just see a counter next to the file name getting incremented on clicks.
@VishwaProtimBanerjee
@VishwaProtimBanerjee Год назад
So I have a habit of pausing the video and trying it out on my own. As soon I saw him doing event handling, I paused the video and started writing the code myself. I mean, easy-peasey 😜 , what could go wrong with JS ? And I added this : onClick = {clickHandler()} - I reloaded and saw the console log already there without the button being clicked - got my answer as soon as I resumed at @3:17 🤦‍♂ Long Live JavaScript!
@adeebahmed1067
@adeebahmed1067 14 дней назад
don't let the curiosity die my friend!
@salsabilalailyrahma3251
@salsabilalailyrahma3251 3 года назад
Thank you sir. I can understand from your explanation. It's really helpfull to do my homework. From Indonesia
@davidsierowski8021
@davidsierowski8021 4 года назад
it's a little strange looking at this when being a java script developer for years, whats the best way to add multiple events of the same trigger.
@lauraochoa96
@lauraochoa96 4 года назад
Just wanna say you're a great teacher. Thanks
@ddg1972
@ddg1972 4 года назад
You´re number ONE!!! You born to teach!
@Human_Evolution-
@Human_Evolution- 3 года назад
Class and Functional Components. Perfect. Wish everyone would do that. Also, upload in 1080p.
@moonacoders160
@moonacoders160 4 месяца назад
More and clear knowledge in just 7 Mints... Just Wow😊
@simple8810
@simple8810 3 года назад
One thing I will add here even me at first glance got confused that ,Sir used function keyword ( function eventHandler () ) in function base components but didnot use that when using class i.e , eventHandle(){ console.log("button clicked") the reason is it is same syntax as or pure Js for classes like we add method in Js class like getResult(){ console.log("hello")} so functions are method in classe,no need of using function keyword hope this help
@madhuvarun2790
@madhuvarun2790 3 года назад
Hi, I have a doubt. Please see the below code. import React, {Component} from 'react'; class Counter extends Component{ constructor(props) { super(props) this.state = { counter: 0 } } incrementCounter(){ this.setState({ counter: this.state.counter + 1 }, () => console.log("count increased to ", this.state.counter)) } render() { return Count - {this.state.counter} this.incrementCounter()}>Increment } } export default Counter; When I run the above program, count increases by 1 when I click the button. But according to the tutorial when I remove parantheses to the incrementCounter the counter doesn't increase. Can anyone explain when?
@nganweiloong1506
@nganweiloong1506 2 года назад
U need to use bind
@giovannimesquita
@giovannimesquita 3 года назад
The best React JS tutorial ever!
@nouralsatari6424
@nouralsatari6424 3 года назад
Hi I'm following your videos step by step and i have a question, why didn't you use arrow function in the handler same as you did in video 10 &11 ? and can we? thank you so much
@aeliazafaasheira3238
@aeliazafaasheira3238 Год назад
what is the different if i remove export or not removing export inside class component? I still dont get it :(
@ankush_in_sync5998
@ankush_in_sync5998 3 года назад
I have a question. here you said we are not using round brackets as the it will be the function call. so, why in previous videos of counter we used this.changeMessage()}> There we used round brackets ? why?? please Explain??
@sergeseva
@sergeseva 4 года назад
Thanks a lot for your awesome course. I wonder why in the functional component you used the word "function" (function clickHandler()), while in the class one not (clickHandler()). Cheers!
@soumiklaik5758
@soumiklaik5758 3 года назад
in a class you dont have functions, there are methods
@poojaborhade7690
@poojaborhade7690 3 года назад
Very helpful series on react.... thankyou sir
@toubashahzad1206
@toubashahzad1206 5 лет назад
Hey thanks for the video. Amazing . I just had one question. In setState video while calling increment(), why did we have to use arrow function and here in class we just used this.functionName. I tried increment thing this way but it gave an error. Kindly explain! Thanks
@gautamsharma9823
@gautamsharma9823 5 лет назад
just go through the next tutorial (video 14 ). you will get the solution.
@ronjones1587
@ronjones1587 5 лет назад
Yes, we have the same question... I hope he answers..
@tubepankajyou
@tubepankajyou 3 года назад
Perfect tutorial. Thank you Vishvas 👍
@kshitizshah6685
@kshitizshah6685 4 года назад
if we type js function after export in class component,and use event handler as functionone()}> it works.....Is it good way to do it?
@poojakushwah5212
@poojakushwah5212 3 года назад
exactly in the prev video, he did that too.
@TrackBlazer5
@TrackBlazer5 3 года назад
Left side para thesis doesn't effect..but don't put right side one
@jamalxd5647
@jamalxd5647 Год назад
3:50 if we have to put parameter on button what should we do?we can't use () at onClick right?
@nithin9183
@nithin9183 2 года назад
Why should we not use braces in event handling and why should we use braces in method
@mihajloilic5836
@mihajloilic5836 4 года назад
Is it wrong to do it this way, it's working: function kliknuto() { alert('Button is CLICKED!'); } function overovano() { alert('Button is HOVERED!'); } function EvHandler() { return ( kliknuto()} onMouseOver={() => overovano()}>Dugme ) } ???
@ЄгорБоденчук-Пастухов
Dude, thank you for this perfect tutorial!!
@aeronwolfe7072
@aeronwolfe7072 Год назад
Can anyone answer this question for me? (thanks in advance) ..... in the Class Component, at 4:40 , why do we NOT need the constructor and call to super() ??? i thought we needed those for call components? apparently i missed something. :/
@JS-ih2lx
@JS-ih2lx 4 года назад
I have a query. Please resolve it. When we assign the onClick event handler with a function call, then why does it not log to the console on being clicked? What are the internals of having an event handler as a function call?
@Himanshu_Sharma..
@Himanshu_Sharma.. 4 года назад
Hope this helps : see when you add parentheses with a function name like this ->fun() JavaScript treat this like a function call and automatically calls the function so when the component renders the function is already called . so now whether you click the button 1 time or multiple times it won't work because react will not re-render the component that is because react consider the function call on the time when it was render for the first time that's why .
@JS-ih2lx
@JS-ih2lx 4 года назад
@@Himanshu_Sharma.. Thanks for the elaborate explanation! I have one more question. Please answer if you can . suppose I have an array defined in this.state={arr:[]} and onClick of a button I want to push no. of times button clicked to arr then how can we do it? Basically I am confused with updating state of an array when an event is fired.
@dinnusebastian4615
@dinnusebastian4615 4 года назад
Why in class component we are not using function keyword??.I mean why u are not writing function clickhandler()
@Himanshu_Sharma..
@Himanshu_Sharma.. 4 года назад
Because functions in class are methods and not regular function as well as they are the part of the class. Also I am adding this : you cannot define a function inside render in a normal way you can only use arrow functions
@KanecoV
@KanecoV 3 года назад
any reason why you wrote "function clickHandler() {}" for the Functional component and just "clickHandler() {}" for the class component?
@simple8810
@simple8810 3 года назад
cause it is pure Javascript Syntax if you had read about how to use class in Js and how functions (means method) are added in That class so the same rule here too like there means in pure js we can use like getResult(){ console.log("hello")} so this is how function(we can it method in class) are used in class
@MounikajallipalliRG
@MounikajallipalliRG 2 года назад
I had a doubt why we used function keyword for clickHandler in fuctional component and y not used function keyword in class component
@coadingwithpandeyji
@coadingwithpandeyji Год назад
Can anyone tell me is class components are necessary when we are good with functional
@SepSol75
@SepSol75 4 года назад
Great video!! btw at 2:26 what font are you using which automatically converts => to an arrow?!
@codeblooded6760
@codeblooded6760 4 года назад
Can you plz elaborate whats the difference in function and function call in event handler? Whythey behave different?
@simple8810
@simple8810 3 года назад
function call means without clicking that console will be run but function means that function is linked with event not direct call
@miss13688
@miss13688 Год назад
I really like the series so far. I am having a bit of confusion earlier in onClick(eg. Counter.js) we were passing an arrow function to call the handler but here we are just calling it by name. How do we differentiate when to use what.?
@aeronwolfe7072
@aeronwolfe7072 Год назад
I am not an expert, but I will try to answer your question. if you define a function, which does not take any arguments, then you can give just the handler the function name, like onClick={functionName}. but if the function needs arguments, then you would have to use parenthesis to pass it like onClick={functionName('hello')}. once you do this, it is calling the function. so it returns void. but the onClick handler needs a function, not void. so you would have to use arrow function syntax if you need to pass an agurement. try it in vscode yourself, define function functionName() { console.log('hello') } and you can then use onClick={functionName} . Now, define function functionName(name){ console.log(name)}, and vscode will error saying the function call is returning void and thats the wrong type for the onClick handler. but if you use onClick={()=>functionName('Steve')} then your giving the onClick handler what it wants, a function. an anonymous one, but a function nonetheless.
@aeronwolfe7072
@aeronwolfe7072 Год назад
i think as soon as you put those parenthesis in there, it makes it a call to a function, not a reference to a function.
@pandu7820
@pandu7820 Год назад
@@aeronwolfe7072 It means normal function only returns void we can change the return type right?
@muneeswarreddy1129
@muneeswarreddy1129 2 года назад
your teaching is Awesome Man, I Really love this Tutorial
@AnkitSharma-jf9fg
@AnkitSharma-jf9fg 3 года назад
Why it gives error if we write function before click handler in class component
@christosam5374
@christosam5374 3 года назад
You are the best Teacher ❤️🙏🏻
@socialbarsha3303
@socialbarsha3303 5 лет назад
Sir what should i do to bringfunctional component by typing rfce? I mean which plugin should i install ?
@Codevolution
@Codevolution 5 лет назад
ES7 / React / Redux snippets
@divyanshupreti3434
@divyanshupreti3434 4 года назад
@@Codevolution I used 'ES7 / React / Redux snippets', but it didn't work. For me 'ES7 React/Redux/GraphQL/React-Native snippets' worked.
@rushabhmandvekar4411
@rushabhmandvekar4411 4 года назад
Even if i write onClick={clickHandler} rather than onClick={this.clickHandler} in js file for it is still giving the same output. I want to know is there any difference or something..? Pls pickup.
@deepaktiwari7059
@deepaktiwari7059 3 года назад
its because when you are using this keyword outside the class its refferring to window . so in short it's make no difference outside class .
@zhenduan9138
@zhenduan9138 3 года назад
is not correct to write something like the following? class MyComponent extends Component{ function myFunction(){ } } Have to remove function, only keep myFunction()?
@jeffmuteru8583
@jeffmuteru8583 2 года назад
What if you do a function call inside an anonymous function? clickHandler() }>Click
@suryakumar9190
@suryakumar9190 4 года назад
One doubt, You put paranthesis in previous video for incrementing the counter?
@surbhibaranwal9749
@surbhibaranwal9749 4 года назад
In that video, he was doing function call but here he wants event handler to be just a function not making the call to the function.
@himanshunegi3216
@himanshunegi3216 4 года назад
Is it necessary to create button in the same file in which i have my function. What if my button is in different file along with other component and i want to link the onClick fucntion which is in different file? How do i do that. I'm new to react, pls help me out.
@addybeez3277
@addybeez3277 2 года назад
I dont know its an update in React i guess but we can't name FunctionClick for file now;...
@sakerevanth7772
@sakerevanth7772 4 года назад
Thanks you sir, but I have a question in setState() topic for updated value by using onClick=()👈-(that method name with paranthasis) . but in this video your using without parenthesis . Here also doing onCilck. How it is sir ...?
@Himanshu_Sharma..
@Himanshu_Sharma.. 4 года назад
Yeah so what actually happens is when you put parentheses on a function it gets called on that place automatically so what happend on that video was when he clicked on the button the arrow function started and since the increment function had () the increment function got called automatically .so basically it's just another way of calling a function indirectly , I hope you understood . By the way great catch !! I was looking for this comment
@gowthambhat1498
@gowthambhat1498 4 года назад
@@Himanshu_Sharma.. I'm also looking for the same comment, thanks man
@ashish23081991
@ashish23081991 4 года назад
How can I pass an argument to event method?
@programmingforfun4158
@programmingforfun4158 2 года назад
The best guy for react for sure.
@anil-wo2ow
@anil-wo2ow 4 года назад
best resources in the internet ( include purchased with money)
@lathagm666
@lathagm666 11 месяцев назад
completed video 13. Thank you 🙂
@wahebbenzaid2591
@wahebbenzaid2591 4 года назад
I did the same thing like you , but the button don't displayed when I had execute the project !! help please
@oliveranderson7962
@oliveranderson7962 3 года назад
Man, this was so helpful. Thanks a lot!! ♥
@AkhilaChilukuri-hq9ps
@AkhilaChilukuri-hq9ps Год назад
can we write the handler in onClick as arrow function notation like in the previous video of state
@ajilkjohn1399
@ajilkjohn1399 Год назад
yes you can---> { function clickHandler() { console.log("Button clicked") } clickHandler( ) --->here u have to call the function else this function won't be called } }>Click This is not suggested bcoz this makes the code difficult to read.
@BharatSingh-zk8lx
@BharatSingh-zk8lx 5 лет назад
I have a doubt, in the previous video where we created the subscribe button, we placed the parentheses, why?
@ciaranwhyte4088
@ciaranwhyte4088 5 лет назад
He made a mistake id bet but agree i found it confusing too
@MuhammadUsman-rp3ph
@MuhammadUsman-rp3ph 4 года назад
he was using arrow syntax of which you have to put paranthesis
@vishalsyoutube
@vishalsyoutube 4 года назад
According to MDN, when an arrow function returns an object literal expression you need to parenthesize the body of the function
@LearnWithNoor036
@LearnWithNoor036 Год назад
in functioncClick : function clickHandler() { console.log("button clicked"); } In classClick : handleClick() { console.log("inside class click"); } What is the difference between these two ? can anyone explain it ?
@TheWilDOn31
@TheWilDOn31 11 месяцев назад
you don't use the keyword 'function' in class. In class you have methods, not functions ..
@harishkanna6079
@harishkanna6079 3 года назад
In a normal HTML application, we pass the event handler along with the round brackets inside double-quotes. What is the difference between that and passing the function reference inside curly braces in react?
@simple8810
@simple8810 3 года назад
We also Use function reference when you do that in pure Jaavascript not in html coding and for curly braces that is react syntax like other lang have,
@yunaf4609
@yunaf4609 3 года назад
wow I spent like 3 hours pulling my hair out because I could not get onclick to work, turns out I had it in lower case instead of camel case, this is such a small thing that all the other youtubers and articles miss
@waelslogga2744
@waelslogga2744 Год назад
why we did'nt use arrow function to create handlers? any help?
@ajilkjohn1399
@ajilkjohn1399 Год назад
you can use--> { function clickHandler() { console.log("Button clicked") } clickHandler()--->here u have to call the function else this function won't be called }}>Click not suggested bcoz code is difficult to read so better define the function outside
@MikeMike-ms1ns
@MikeMike-ms1ns 3 года назад
what if you want to pass a value to an event handler?
@amartanwar6725
@amartanwar6725 5 лет назад
In SetState video we did event call and we called method using parenthesis, Why we did not use this.fucntion there? Can somebody help me.
@saadbaig3060
@saadbaig3060 4 года назад
@Gabriel Daniluk thanks man
@sahithreddy2203
@sahithreddy2203 4 года назад
​@Gabriel Daniluk That helped man!! Thanks a lot!!
@Himanshu_Sharma..
@Himanshu_Sharma.. 4 года назад
Here is the explanation of the answer in the reply.... Yeah so what actually happens is when you put parentheses on a function it gets called on that place automatically so what happend on that video was when he clicked on the button the arrow function started and since the increment function had () the increment function got called automatically .so basically it's just another way of calling a function indirectly , I hope you understood .
@marynungari6524
@marynungari6524 4 года назад
This tutorial is AWESOME, Thank you so much
@vinayajmd
@vinayajmd 3 года назад
I'm a beginner in React and I couldn't have asked for a better start
@harshbhojwani1794
@harshbhojwani1794 4 месяца назад
Another superb video
@Siddharth-yi7pg
@Siddharth-yi7pg 3 года назад
Can we use using event listeners
@SurajKumar-bw9oi
@SurajKumar-bw9oi 2 года назад
Do any of you guys know emmet or other shortcut for writing console.log("") in VisualStudio Code?
@rohitbagadi3058
@rohitbagadi3058 2 года назад
log+enter
@RakeshKumar-zj4hu
@RakeshKumar-zj4hu 4 года назад
this anemia :(:(:( Vishwas I wanted to use arrow function instead of regular function on clickHandler. For Functional component const FunctionClick = () => { const clickHandler = () => { console.log('Clicked'); }; return ( Click ); }; For Class component class Classclick extends Component { const clickhandler = () => { console.log('Clicked'); }; render() { return ( Pls Clicke Me ); } } This throws me an error. I had to change const clickhandler to just clickhandler. What is going on???
@ajaypadwal4619
@ajaypadwal4619 3 года назад
Are there any notes made for the whole series?
@vaibsify
@vaibsify 2 года назад
awesome explanation 🙏
@tiagomelo3197
@tiagomelo3197 2 года назад
I'm very new at this, I'm working on learning React Native, and I can't seem to wrap my head around how the hell i should work with events outside my file. I'm currently working on an exercise that asks me to create all my components separately. I have created a file (Input.js) where i have a password input that has a function where I can access the input text the user is texting, but i can't access the event, and the event changes on my Button.js file, anyone able to help???? I'm so stuck on this one, i'd like to avoid using redux or external libraries because i've been told it's possible in this scenario! PLEASE SAVE ME FROM THIS MISERYY!!
@612_somnathmalik3
@612_somnathmalik3 3 года назад
Thank you sir for such videos.
@Aditya.Santra
@Aditya.Santra 3 года назад
Very Helpful Video ❤️
@emmanuelatienza8706
@emmanuelatienza8706 4 года назад
Your tutorials are awesome!!
@ianpaul0520
@ianpaul0520 3 года назад
how bout insertion of parameters into that method?
@developerwithalife2313
@developerwithalife2313 4 года назад
is this vishvas who is tutor for this video sounds different to me?
@orenvaknin846
@orenvaknin846 4 года назад
Thanks for your videos! you are amazing!
@dominiquehatoun
@dominiquehatoun 4 года назад
Man, you are great! Thanks a lot!
@arnabdas7145
@arnabdas7145 4 года назад
how to add css to these js files (Component ) ? :-/
@MuhammadUsman-rp3ph
@MuhammadUsman-rp3ph 4 года назад
simply import them like "import from "./style.css' "
@vigneshgvs
@vigneshgvs 2 года назад
Can create a function inside another function in functional/class component : onclick="myFunction()" vs onClick={myFunction} if added parantesis at end - {myFunction()} - it becomes function call - and method gets called, even before calling..... WoW...... also if its arrow function, ( ) is allowed, next video if its class: onClick={this.myFunction}
@aryantripathi8275
@aryantripathi8275 3 года назад
those code snippets are not working
@urgensherpa
@urgensherpa 4 года назад
You're a fucking genius dude. So clear in your explanations damn
@sandeepvamanbende8121
@sandeepvamanbende8121 3 года назад
You are a gem 💎
@benediktlantsoght1706
@benediktlantsoght1706 4 года назад
Thank you Sir!
@dontbetoxic4387
@dontbetoxic4387 3 года назад
thank you sir
@sheerasai5948
@sheerasai5948 3 года назад
excellent 👍🏻
@ChandraPrakash-vq4re
@ChandraPrakash-vq4re 4 года назад
Thanks, it is working
@AxxionMarketPlace-iu6ri
@AxxionMarketPlace-iu6ri Год назад
Thank you
@KevinTempelx
@KevinTempelx 3 года назад
Thanks!
@codeblooded6760
@codeblooded6760 4 года назад
Plz make a video on drag and drop of elements
@walideker2253
@walideker2253 Год назад
ntaaa chiikourrrrr tysm
@natture
@natture 3 года назад
I am on a go now asm content
@achalchoudhary9864
@achalchoudhary9864 4 года назад
Please create a video explaining synthetic event
@דולבדובלון
@דולבדובלון 4 года назад
love you very much
@ShubhamKumarPandeyshubhkaira21
@ShubhamKumarPandeyshubhkaira21 3 года назад
Please help me to install these es7 code snippets Anyone?? @Codevolution
@navjotsingh2457
@navjotsingh2457 2 года назад
ty
@AhamedKabeer-wn1jb
@AhamedKabeer-wn1jb 2 года назад
Thank you..
Далее
ReactJS Tutorial - 14 - Binding Event Handlers
11:56
Просмотров 580 тыс.
ReactJS Tutorial - 10 - State
10:35
Просмотров 903 тыс.
Собираю Маню к осени ✨
00:48
Просмотров 599 тыс.
ReactJS Tutorial - 12 - Destructuring props and state
4:45
ReactJS Tutorial - 16 - Conditional Rendering
11:46
Просмотров 489 тыс.
ReactJS Tutorial - 19 - Index as Key Anti-pattern
11:00
ReactJS Tutorial - 9 - Props
11:37
Просмотров 1 млн
ReactJS Tutorial - 15 - Methods as props
8:45
Просмотров 497 тыс.
This Is How You Handle Events In A React App
9:15
Просмотров 5 тыс.
ReactJS Tutorial - 11 - setState
14:30
Просмотров 761 тыс.
5 JavaScript Concepts You HAVE TO KNOW
9:38
Просмотров 1,4 млн