React Refs and DOM

Поделиться
HTML-код
  • Опубликовано: 14 дек 2024

Комментарии • 128

  • @TheLuckyExplorerAu
    @TheLuckyExplorerAu 4 года назад +10

    From React 16.3 on wards, if you are using ref, do below.
    constructor(){
    super();
    this.firstName = React.createRef();
    }
    Then in the input field
    ref = {this.firstName}
    To access the value: this.firstName.current.value

    • @Aman-Verma
      @Aman-Verma 3 года назад +3

      or better use react hooks, just simply asign any const = useRef(null), and then use that const in the element as ref={name of the const} ;)

  • @gabrielfono844
    @gabrielfono844 4 года назад +2

    I am pretty sure this channel will get million subscribers by 2021.
    damn, people spend lots of money on udemy because I am pretty sure they dont know this channel.
    I learnt oop in this channel and now I am working hard with react to really master the foundation while learning datastructure and algorithms for my interview at amazon soon.
    I will connect this to my blog so that people can view.
    I will also share this on media, reddit and all the blog that I am connecting on right now
    thanks for this such an amazing content.

    • @biti9648
      @biti9648 3 года назад

      134k subs :)

  • @gonzaloespeche1499
    @gonzaloespeche1499 6 лет назад

    thanks for your constant dedication helping the community with these topics. I started watching you months ago and now, while I'm attending a coding bootcamp, I keep looking at your videos for a better understanding of all the things I`m quickly forced to learn.
    Your way of explaining things line by line, together with a solid deep knowledge of whats going on under hood, makes your channel a true learning gem among other educational channels. Thanks again and I'm sure that your channel will grow further more, as quality, on the long run, pays.
    Whenever I have free time I will translate one of your videos to Spanish in return for your unconditional dedication!

    • @Techsithtube
      @Techsithtube  6 лет назад

      I appreciate the offer for translation. Currently i don't have any video translated to Spanish so this would be a good addition. THanks for watching and for your support.

    • @gonzaloespeche1499
      @gonzaloespeche1499 6 лет назад

      Great then! Do you have any particular video you would like to have it on Spanish?

  • @yornadnaps4602
    @yornadnaps4602 3 года назад

    @techsith, this is a really unique video about refs in-depth. Its a one-of-a-kind video I have watched among so many videos on refs in general where a quick sweep of useRef() hook is done & the video eventually ends.
    Thanks for explaining this so clearly!!!
    Keep up the great work!
    You fan,
    Yor

  • @bhaktiwangade3581
    @bhaktiwangade3581 6 лет назад

    Best thing about your videos is you explain concepts in simple words and with a small example , so that its easy to understand for beginners . I definitely recommend your videos to everyone who wants to learn REACT . ..WORTH watching .... Also it will be great , if you can make a small project which has basic CRUD operations . .....Thank you

  • @АндрейСарнавский-у9т

    Wow, Indian with good English. Thank god!

  • @pythonpsql8572
    @pythonpsql8572 6 лет назад

    Many thanks. Its so frustrating when you are new to something and cannot do presumably simple things like navigating to the next input box with the enter key. Keep up the good work!

  • @TiE23
    @TiE23 5 лет назад +1

    Nice. I made an entire website in React in a span of seven months and only now do I understand what the heck refs are. Thanks.

    • @Techsithtube
      @Techsithtube  5 лет назад

      most of the people dont use refs until when they have to and there is no other alternative. :)

  • @ChristanFoden
    @ChristanFoden 5 лет назад +1

    You should mention in the title that you address refs in stateless functional components. Good tuts man!

  • @faisalnaseer798
    @faisalnaseer798 6 лет назад +1

    im puzzled when to use this.inputRef.current.focus() vs
    this.inputRef.focus()..because sometimes when code is not working without current i change it to current and vice versa

  • @BillyCandles
    @BillyCandles 5 лет назад +1

    Nice video. Clear, concise and to the point. Keep up the great work.

  • @akatsuki_ninja33
    @akatsuki_ninja33 5 лет назад

    Couldn't understand why to use props in myinput 18:36

  • @Aman-Verma
    @Aman-Verma 3 года назад +1

    with react hooks we can simply write as...
    const firstNameRef = useRef(null)
    and then use firstNameRef as a value to ref attribute of element.

    • @Techsithtube
      @Techsithtube  3 года назад

      Yes this is old way of doing things. hooks makes it much simpler.

  • @ОлегКвашнин-ъ9ф
    @ОлегКвашнин-ъ9ф 6 лет назад +4

    17:31 - that was pretty tricky =)
    It took me a couple of minutes to realize that you clipped the video and cut off the part where you added "const" to "onClick"...

    • @olgaskripnikova1881
      @olgaskripnikova1881 5 лет назад +1

      Thank you, Oleg, for this comment. I couldn't understand why my code didn't work. It helped me.

  • @elfpimp1
    @elfpimp1 6 лет назад +1

    Do you have any tutorials on Mongoose or montDB??

  • @rohanshastri944
    @rohanshastri944 4 года назад

    whether the keyCode has been deprecated these days?

  • @ashish.sharma.87
    @ashish.sharma.87 6 лет назад +5

    As good as any other video from you. A big like.

  • @snjvthakur24
    @snjvthakur24 5 лет назад

    how to move to next input on dynamic inputs

  • @RohitVerma-wn5lz
    @RohitVerma-wn5lz 6 лет назад

    there is an error on 17:30 in this video

  • @techRadiants
    @techRadiants 6 лет назад

    Can you please explain that How does the "bind(this , "firstName")" works?

  • @suhasnayak4704
    @suhasnayak4704 6 лет назад

    You said you will be explaining when to use and when not to use ref, but you did not cover it ! You just covered one use case, anyway thank you.

  • @ayeshaazam3378
    @ayeshaazam3378 5 лет назад +1

    Good tutorial, easy to understand. Thanks for the video

  • @shyarxelil1987
    @shyarxelil1987 6 лет назад

    I like your description easy to be understood and obvious! good job keep it up!

  • @ruchirai5775
    @ruchirai5775 5 лет назад

    what is the difference between I create reference in constructor and then use it in html versus callback.Eg I can write something like this -
    this.firstName = React.ceateRef() and I can use ref = {this.firstName} in html I have tested and it works in react 16 and 16+

    • @Techsithtube
      @Techsithtube  5 лет назад

      yes it works. as react is very forgiving but they dont recommend using it that way. Eventually they will completely deprecate it.

  • @pulkitjoshi2963
    @pulkitjoshi2963 4 года назад

    what is input variable ? in refs ? How it goes in the function? Does it have to be tag name?
    Thanks

    • @Techsithtube
      @Techsithtube  4 года назад

      Input variable is nothing but input props. you can pass into a function.

  • @Mateoi2335
    @Mateoi2335 4 года назад

    I'm getting undefined in the console when I try to console log the state ( 7:24 )

    • @Techsithtube
      @Techsithtube  4 года назад +1

      you are saying that this.firstName is giving you undefined? That means its not accesible or available. Without looking at your code Its hard to say why.

    • @Mateoi2335
      @Mateoi2335 4 года назад

      @@Techsithtube I solved the error by setting the value with this.satate.exemple and changing it with onChangeHandler.

  • @muhammadqamar2283
    @muhammadqamar2283 5 лет назад

    Documet.getElementBy.... etc is doing same thing? What is main differnece then

    • @Techsithtube
      @Techsithtube  5 лет назад

      In react you dont access elements directly . you do it react way.

    • @muhammadqamar2283
      @muhammadqamar2283 5 лет назад

      @@Techsithtube but it is possible. Am I ri8?

  • @shashankgupta006
    @shashankgupta006 6 лет назад

    Hi Sir, for me , after following the same procedure , "Cannot read property 'keyCode' of undefined react js" error is coming, please suggest.

  • @usamabarlas1605
    @usamabarlas1605 6 лет назад +1

    it's a mistake that's shows me (inputRef.focus();) on 17:30 mnt

    • @Techsithtube
      @Techsithtube  6 лет назад

      What version of react are you using? There is a change

    • @usamabarlas1605
      @usamabarlas1605 6 лет назад

      @@Techsithtube v 16.7.0

  • @abdulrehman-rt5mz
    @abdulrehman-rt5mz 6 лет назад

    why you used bind here?onKeyUp isnt a arrow function?and arrow function doesnt need this binding i think?

    • @Techsithtube
      @Techsithtube  6 лет назад

      We dont need binding there, however if you want to pass parameters this is a one way of doing it.

    • @abdulrehman-rt5mz
      @abdulrehman-rt5mz 6 лет назад

      @@Techsithtube ohh got it thanks

  • @DarrylHebbes
    @DarrylHebbes 6 лет назад

    Awesome tutorial... Also glad you shortened the intro animated logo segment

  • @411sev
    @411sev 5 лет назад +1

    Thanks you very much. I like your method of explain tricky concepts using simple and easy to follow examples..

  • @keithcarrillo8238
    @keithcarrillo8238 6 лет назад

    @4:51 Hey TechSith. Did you say 'this' is deprecated or did I miss something?

    • @Techsithtube
      @Techsithtube  6 лет назад +1

      what i mean to say is ref="someref" is deprecated. instead string ref you have to use a callback function.

    • @keithcarrillo8238
      @keithcarrillo8238 6 лет назад

      oooh ok. Thanks

  • @ramagirisrikanth3583
    @ramagirisrikanth3583 6 лет назад

    In my case i have dynamically repeated radio button is there. am getting all the refs in did mount, and am checking true to only one radio button but it is not getting affected even checked true there in that (debugging)

    • @Techsithtube
      @Techsithtube  6 лет назад

      So you want only one ref?

    • @ramagirisrikanth3583
      @ramagirisrikanth3583 6 лет назад

      techsith no i need all the refs (i.e., dynamycally looping radio element ) and need to change one element with condition, i got all the ref in a variable but when am trying to change one ref dom is not updating. Hope u understood my senario

  • @kimberlyjohnson2305
    @kimberlyjohnson2305 6 лет назад +1

    Really clarified refs. Much appreciated!

  • @brittonwalker7341
    @brittonwalker7341 5 лет назад

    Hey +techsith, I found this very helpful. Thank you for taking the time to make this video.

    • @Techsithtube
      @Techsithtube  5 лет назад

      Appreciate the comment Britton . Keep on learning

  • @amylee1485
    @amylee1485 5 лет назад

    Awesome video! and really clear explanation

  • @satyajeetkumarjha1482
    @satyajeetkumarjha1482 5 лет назад

    The best use case of refs is changing the state of child component from the parent component.

  • @SolutionHunterz
    @SolutionHunterz 5 лет назад

    really good video to learn about refs. I am just wondering, how do we access ref from child to parent component ?

    • @Techsithtube
      @Techsithtube  5 лет назад +1

      You have to use forwarding ref . I have a recent tutorial on forwarding ref that you can check it out. I am using it with hooks but you can use it without hooks.

  • @caseykhuc9304
    @caseykhuc9304 5 лет назад +1

    Such a cool tutorial. Much appreciate 😎😎

  • @naveedurrehman1059
    @naveedurrehman1059 4 года назад

    Sir i am new to react my background is as a mobile developer.
    i have question how to pass reference to Third party plugins like
    I know how to pass in but not working in floating case not getting focus on reload.
    Its says current.focus(); is not a function.
    i can share my code snippet via email address

    • @Techsithtube
      @Techsithtube  4 года назад

      Sure feel free to send me the code.

  • @SudhanshuRamTripathi
    @SudhanshuRamTripathi 5 лет назад +1

    You can pass field Name where you want to set focus and avoid switch conditions
    like: onClick={this.onClick.bind(this, 'lastName')}
    and in function def we can write:
    this[target].focus(); , So in this way we can avoid multiple switch conditions.
    Are you agree ??

  • @ayeshaazam3378
    @ayeshaazam3378 5 лет назад

    Hi , I have tried to follow your Tutorial, But it not working for me, the changes I have done is followed the react 16.3 version so now i can do like this: this.firstname = React.createRef(); and then when rendering it I had Arrow function
    ( as because => arrow function does the binding thing)so my code look like:
    FirstName:
    {
    this.onKeyUp("firstname");
    }}
    />

    So I want to know Why my code is not working. Thanks in advance!
    my whole code:
    export default class Forms extends Component {
    constructor(props) {
    super(props);
    this.firstname = React.createRef();
    this.lastname = React.createRef();
    this.age = React.createRef();
    this.submit = React.createRef();
    }
    onSubmitHandler = e => {
    console.log("this.firstname", this.firstname.current.value);
    };
    onKeyUp = (target, e) => {
    if (e.keyCode === 13) {
    switch (target) {
    case "firstname":
    this.lastname.current.focus();
    break;
    case "lastname":
    this.age.current.focus();
    break;
    case "age":
    this.submit.current.focus();
    break;
    default:
    this.firstname.current.focus();
    }
    }
    };
    render() {
    return (
    FirstName:
    {
    this.onKeyUp("firstname");
    }}
    />

    lastName:
    {
    this.onKeyUp("lastname");
    }}
    />

    Age:
    {
    this.onKeyUp("age");
    }}
    />
    this.onKeyUp("submit")}
    onClick={() => this.onSubmitHandler}
    />
    );
    }
    }

  • @gahlyogu4570
    @gahlyogu4570 4 года назад

    14:30 "anyways .. you get the point"
    actually no , I didn't get the point the part of demonstrating `alert()` instead of `console.log()` xD

  • @yasirarsalan8586
    @yasirarsalan8586 5 лет назад +1

    you are really good , you solved my problem.

    • @Techsithtube
      @Techsithtube  5 лет назад

      I am glad that it helped. Thanks for watching Yasir!

  • @rich_bear
    @rich_bear 6 лет назад +2

    Thank you for this great tutorial!

  • @enthupanda
    @enthupanda 6 лет назад

    Hi TechSith, Could you make a video on ASYNC AWAIT

  • @cezar007dead8
    @cezar007dead8 5 лет назад +1

    Thank you for this video. It helped me a lot!

  • @GauravJoshi-Vlogs
    @GauravJoshi-Vlogs 6 лет назад

    Very Nice Video..Learned a lot..thnx!!

  • @jocsanmairena4222
    @jocsanmairena4222 4 года назад

    Great tutorial. Thank you for sharing.

  • @cyrusbesabella5938
    @cyrusbesabella5938 4 года назад

    I cant believe this is free! thanks again sir!

  • @akhileshpips
    @akhileshpips 4 года назад

    imagine this guy standing behind you in crowded metro, whispering react in your ears

  • @troygooden2525
    @troygooden2525 4 года назад

    Appreciated this. Thank you.

  • @winfredj9820
    @winfredj9820 6 лет назад

    just today i was looking at refs in my new project

  • @md.fazlulkarim8847
    @md.fazlulkarim8847 6 лет назад

    I just push the youtube bell icon for the first time in forever

  • @riongull
    @riongull 5 лет назад +1

    His follow up video for dealing with refs in function components and hooks: ruclips.net/video/ScT4ElKd6eo/видео.html

  • @TFlies
    @TFlies 6 лет назад

    Tell me how to be as smart as you are......watched tons of tutorials and yours are the best.

    • @Techsithtube
      @Techsithtube  6 лет назад

      Thanks for the nice comment. All you have to do is to understand fundamentals and everything else becomes easy.

  • @mateshwari33
    @mateshwari33 4 года назад

    best tutorial ...thank you sir

  • @alexanderalancahutay4821
    @alexanderalancahutay4821 6 лет назад +2

    One of the best thank you so much!

  • @rustamthor96
    @rustamthor96 6 лет назад

    You are the best! so cool tutorials!

  • @MissSushiBeast
    @MissSushiBeast 6 лет назад

    Very informative - thank you.

  • @yasirarsalan8586
    @yasirarsalan8586 5 лет назад +2

    you are really , you solved my problem.

  • @gordankondev7948
    @gordankondev7948 6 лет назад

    Great videos.. Maybe better to pass the name of the next input in the class Component as the second parameter, so you do not need a switch statement

  • @nanipoluru
    @nanipoluru 6 лет назад

    Awesome Explanation....as like all

  • @shivananda7249
    @shivananda7249 3 года назад

    Sir,explain about Context Api

  • @codito7388
    @codito7388 6 лет назад +1

    Techsith i like your explanation.Why don't you make a real app website in react after all thes fundamental?With real app everyone will understand react better because you explain it good and if someone make good explanation,sooner or later will get more and more reviews.We are waiting for a real app.

  • @akashagarwal3213
    @akashagarwal3213 6 лет назад +1

    the best react tutorial i have seen

  • @ОлегКвашнин-ъ9ф
    @ОлегКвашнин-ъ9ф 6 лет назад

    Nice videotuts though.
    Keep up the good work!

  • @himalayanKapoor
    @himalayanKapoor 4 года назад

    2020 depreciated

  • @mohangopals
    @mohangopals 6 лет назад

    Nice explanation.

  • @SunilKumar-fh6jk
    @SunilKumar-fh6jk 6 лет назад

    Hey sir please make tutorials on express.js and MongoDB please!

  • @蘇啟賢-i9y
    @蘇啟賢-i9y 6 лет назад

    Helpful, thank you.

  • @Phloteck
    @Phloteck 6 лет назад +1

    Good tutorial.

  • @ashse4424
    @ashse4424 5 лет назад +1

    you are the best

  • @shamseerahammed4094
    @shamseerahammed4094 4 года назад

    good one !

  • @mihai1225
    @mihai1225 4 года назад

    You have a strong american accent

  • @srudabdulrahman9608
    @srudabdulrahman9608 6 лет назад

    thank you

  • @sajankumar-xk2vj
    @sajankumar-xk2vj 6 лет назад

    You don't have to use switch case. Instead if(e.keyCode === 13) { this[target].focus(); } simple isn't? :)

    • @Techsithtube
      @Techsithtube  6 лет назад

      on the onChange event you can do e.target. but this is a onKeyPress so you dont have access to input element. also 'this' means the component.

    • @sajankumar-xk2vj
      @sajankumar-xk2vj 6 лет назад

      Oh really! 'firstName'... is the property of component. You can please visit this link to see in action jsfiddle.net/sajankumarv/zga5po1s/13/ Good luck!

    • @Techsithtube
      @Techsithtube  6 лет назад +1

      ohh! this works. Thanks man.

    • @ryanlassiter599
      @ryanlassiter599 5 лет назад

      Maybe you can flesh this out a bit more? this[target] is confusing syntax in my mind. When I see it I think 'this' with an index of target....like you're calling an array item. Can you explain this syntax a little further? Why does this[target] give us the element we wish to focus on?

  • @omermindivanli2981
    @omermindivanli2981 6 лет назад +1

    great

  • @Akshhacks
    @Akshhacks 6 лет назад

    Thanks

  • @daviddonadze221
    @daviddonadze221 6 лет назад

    nice

  • @tubun09
    @tubun09 6 лет назад

    barely watching this and I will tell that React is evil for absolute beginner

    • @Techsithtube
      @Techsithtube  6 лет назад

      Handika start from the beginning level. refs and doms are bit complex if you don't know the basics.

  • @eduparamu5124
    @eduparamu5124 Год назад

    sir try to speak some words clearly. keep in mind that students from rural areas also watch ur videos. So utter it clearly , speak indian english, smile on ur face, think some one is making notes!!!! Thanks for taking advise positively.

  • @andriiauziak1178
    @andriiauziak1178 5 лет назад +1

    nice

  • @bawaparampreet24
    @bawaparampreet24 5 лет назад

    great