React OTP Input Field With Typescript & Tailwind CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ย. 2024
  • MERN Bootcamp: www.udemy.com/...
    In this video we will take a look at how we can create OTP field using react and tailwindcss.
    Starter Codes: gist.github.co...
    Final Code: www.uifreebee....
    Social Media Links
    Instagram - / ndpniraj
    Twitter - / ndpniraj
    Linkedin - / niraj-dhungana-23387b207
    #tailwindcss #react

ความคิดเห็น • 40

  • @wisdomeshiet4259
    @wisdomeshiet4259 2 ปีที่แล้ว +4

    You know a great teacher when the same logic applies to a different concept... Thank you and God bless!

  • @adiodamilare4406
    @adiodamilare4406 10 หลายเดือนก่อน +2

    this is amazing.
    u help me solve the bug that took me four days .
    thank you

  • @kukasn
    @kukasn ปีที่แล้ว +4

    Please if you are using react js you might have issues after follow all the steps just add this block of code to make it work fyn
    const handleOnKeyDown = (e, index) => {
    currentOTPIndex = index;
    if (e.key === "Tab") {
    e.preventDefault();
    setActiveOTPIndex(currentOTPIndex + 1);
    }
    if (e.key === "Backspace" && !e.target.value) {
    e.preventDefault();
    setActiveOTPIndex(currentOTPIndex - 1);
    }
    };

  • @MDMinhazulAlamChowdhury
    @MDMinhazulAlamChowdhury 4 หลายเดือนก่อน

    great tutorial! but I guess, the string slicing method is not required in an OTP field if you just use the maxLength property inside the input tag

  • @pedroh.belchioralves3626
    @pedroh.belchioralves3626 10 หลายเดือนก่อน

    Thanks, it helped me too much, a hug from Brazil!!

  • @jennifermagpantay7933
    @jennifermagpantay7933 2 ปีที่แล้ว +4

    Great explanation and video! Just in time to help me with a task I am working on! Thanks for sharing and congrats for the content!!

    • @jennifermagpantay7933
      @jennifermagpantay7933 2 ปีที่แล้ว

      Also, I figured out another way without the need of onKeydown function and currentActiveIndex variable:
      I have added to handleOnChange if statements:
      if (!value) {
      setActiveIndex(index - 1);
      } else if (activeIndex === otpValue.length - 1) {
      // once activeIndex gets the value of 5, or otpValue.length - 1, it will get this value set as its state.
      // this would avoid the weird behaviour index values
      setActiveIndex(otpValue.length - 1);
      } else {
      setActiveIndex(index + 1);
      }

    • @fsniraj
      @fsniraj  2 ปีที่แล้ว +3

      That's the fun of programming. Same goal multiple solutions.

  • @СергейНадоенко
    @СергейНадоенко 7 หลายเดือนก่อน +1

    Love u bro, thank u so much

  • @iyaremeyo
    @iyaremeyo 2 หลายเดือนก่อน

    Nice tutorial

  • @temitopedavid9508
    @temitopedavid9508 6 หลายเดือนก่อน +1

    Thank you bro

  • @codebreaker2495
    @codebreaker2495 8 หลายเดือนก่อน

    Amazing content and explanation, thanks!

  • @Shoutiez
    @Shoutiez 10 หลายเดือนก่อน +1

    In case of user skip some input let's say [1]-[ ]-[3]-[ ]-[5] when i press backspace at last input (5) the number 5 and 3 not deleted and after debugging I saw that onChange event did not fire but onKeyDown did.
    Do you have any idea how to fix this issue?

    • @Shoutiez
      @Shoutiez 10 หลายเดือนก่อน

      Currently my solution is to check in onKeyDown if the previous input doesn't have value I will remove the value of the current index as code below.
      if (key === "Backspace") {
      if (!otp[index - 1]) {
      const newOtp = [...otp]
      newOtp[index] = ""
      setOtp(newOtp)
      }
      setActiveIndex(currentIndex.current > 0 ? currentIndex.current - 1 : 0);
      }

  • @robertoribeiro9166
    @robertoribeiro9166 10 หลายเดือนก่อน

    That's amazing! Thanks for this tutorial

  • @georgesoriano3580
    @georgesoriano3580 2 ปีที่แล้ว

    Great Tutorial! Thanks more video to come

  • @sallehshah
    @sallehshah ปีที่แล้ว

    Thanks alot , need this component for my day job.

    • @motivationofthemindofc
      @motivationofthemindofc ปีที่แล้ว

      Would you like to make one for entering dates, and a regex to determine the numbers of days, month and year?

  • @AzedineOuhadou
    @AzedineOuhadou ปีที่แล้ว

    thank you for this amazing video

  • @samahgad241
    @samahgad241 ปีที่แล้ว

    thanks alot very helpful and clear

  • @dextreme1754
    @dextreme1754 ปีที่แล้ว

    the first 4 mins of your vid saved me thanks so much I spent like 3 hours to get this shit working by myself but the events registered/fired later so the index was always off for me thanks again :)

    • @motivationofthemindofc
      @motivationofthemindofc ปีที่แล้ว

      Would you like to make one for entering dates, and a regex to determine the numbers of days, month and year?

  • @motivationofthemindofc
    @motivationofthemindofc ปีที่แล้ว

    Would you like to make one for entering dates, and a regex to determine the numbers of days, month and year?

  • @codewithadeveloper
    @codewithadeveloper ปีที่แล้ว

    It was very helpful, thank you

  • @shinnthantminn9758
    @shinnthantminn9758 2 ปีที่แล้ว

    awesome tutorial that was so helpfull for me

  • @eroachiever6883
    @eroachiever6883 ปีที่แล้ว

    Thank you so much. Well detailed!

  • @gauravverma1374
    @gauravverma1374 2 ปีที่แล้ว

    Help!!! I am using this otp input component....when I passing this otp value string or OTP array to its parent comp. Through setstate...its not working

  • @AvtandilShaburishvili
    @AvtandilShaburishvili ปีที่แล้ว

    Well done man, and thanx a lot for hint ^_^

  • @AkshaySingh-uw2kj
    @AkshaySingh-uw2kj 2 ปีที่แล้ว

    I want to start react native. Are you planning to make react native coourse? You have videos on it. But im not sure if that would be enough.

  • @sinatajik8887
    @sinatajik8887 ปีที่แล้ว

    It was a great tutorial

  • @ozzzy9623
    @ozzzy9623 ปีที่แล้ว

    ty! helped a lot

  • @philip.thomas
    @philip.thomas 2 ปีที่แล้ว

    Could u show login and logout in react with out google login

  • @joyentertainment9696
    @joyentertainment9696 ปีที่แล้ว

    Thanks bro 😊

  • @yasserhy
    @yasserhy ปีที่แล้ว +2

    Nice one, but there is a big issue with this video. Unfortunately, you did not provide the full working code for people to check. Getting the code from your video is not easy since you talk too fast and move the screen and cursor quickly which makes it difficult for people to follow.

  • @aravindsanjeev4150
    @aravindsanjeev4150 ปีที่แล้ว

    You cannot copy and paste a verification code to this input box. It will just take the last digit and fill the first input.

  • @soulemotionshorts
    @soulemotionshorts ปีที่แล้ว

    Not good coding practices used. Many features are missing such as pasting of otp.

  • @surojitdas07
    @surojitdas07 11 หลายเดือนก่อน

    i did this with 4 5 lines of coding what a waste of time