Here is another fun beginner React challenge (image slider)

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • 📘 T3 Stack Tutorial: 1017897100294.gumroad.com/l/j...
    🤖 SaaS I'm Building: www.icongeneratorai.com/
    ✂️ Background Cutter: www.backgroundcutter.com/
    💬 Discord: / discord
    🔔 Newsletter: newsletter.webdevcody.com/
    📁 GitHub: github.com/webdevcody
    📺 Twitch: / webdevcody
    🤖 Website: webdevcody.com
    🐦 Twitter: / webdevcody

Komentáře • 44

  • @alexandrepereira6522
    @alexandrepereira6522 Před 11 měsíci +6

    Note for beginners: DRYing up your code comes from Don't Repeat Yourself.

  • @iamsomraj
    @iamsomraj Před 11 měsíci +3

    Love these type of videos! Keep them coming 🔥

  • @auditusich
    @auditusich Před 11 měsíci +2

    Oh, this taks is pretty similar to my default task for react interview. In my case candidate should implement stopwatch with controls.
    Note: more elegant implementation is custom hook based on useeffect+cleanup.

  • @FacundoTroitero
    @FacundoTroitero Před 6 měsíci

    I've been programming for +3 years, in several languages and frameworks and from all the exercises in this series, this is the only one I could (barely) solve on my own. So I guess this is the only one I'd say it's "beginner level"!

  • @vivianliu5011
    @vivianliu5011 Před 6 měsíci +1

    I think there is also a small bug in current implementation, when the slide is looping and the 'prev' or 'next' button are pressed, it messed up with the sildeIndex. I think we should clearIntervals when these two buttons are clicked as well.

  • @OhluhKayTall
    @OhluhKayTall Před 11 měsíci

    another way to make adding the css less of a hassle is to have all the images as separate elements instead of swapping the src, then adding/removing a class to handle the animation stuff depending on the index. Makes the logic a bit easier to follow whenever I'd make something like this in plain javascript

  • @Sky-yy
    @Sky-yy Před 11 měsíci

    Yooo , back at it

  • @cod-the-creator
    @cod-the-creator Před 11 měsíci +2

    The mod thing is cute, but I personally prefer not having that kind of code golf in my repo. The ternary isn't *that* much more code but is way easier to understand at a glance. Just personal preference though, not saying it's right.
    Also when you were talking about the pain of animation the slide, it randomly reminded me of how we used to do hover effects back in the day. People who didn't code back in 2000 or whatever might not know but you used to create a "sprite" for images with transitions (like icons that go from gray to full color on hover) and simply move the image around in the background of the container. IIRC this was the only way back then to have hover effects without blinking. Little history tidbit there lol

    • @WebDevCody
      @WebDevCody  Před 11 měsíci

      Css has come a long way, but it still kind of sucks 😂

  • @brandonsayring
    @brandonsayring Před 11 měsíci

    We could also use the modulo operator to loop through slides in reverse with:
    (SLIDES.length + curIndex - 1) % SLIDES.length

  • @charliesta.abc123
    @charliesta.abc123 Před 10 měsíci

    For beginners another tip for 14:27 would be to return if the interval.current exists then you avoid nesting.
    if(interval.current) return;
    ...

  • @Applecitylightkiwi
    @Applecitylightkiwi Před 11 měsíci

    Interesting that you start at the prev button, because ive learned that we always iterate first, meaning next would have been the easiest to implement. ( intuitively)
    The reason why i mention this because when youbstart with JS classes, theres no such this as this.var.previous
    Or like how we learn in kindergarten to add first then subtract
    I love the % approach, i never really thought about it,
    The challenge was pretty easy, i was worried at one point you would have created an infinite loop there, but you immediately made a function for that.
    Code was really dry appreciate you doing these little challenges

  • @SeibertSwirl
    @SeibertSwirl Před 11 měsíci

    Niccce!!!!! You’re doing great babe! 😘

  • @joshuwa3953
    @joshuwa3953 Před 11 měsíci

    Thanks for react videos

  • @youmnaification
    @youmnaification Před 8 měsíci

    I would disable the Prev button when showing image at index 0.

  • @ProfessionalCarolUnderstander
    @ProfessionalCarolUnderstander Před 11 měsíci

    I kinda wanted to try this on my own before watching the video. Would be cool if we could a link to a codepen or something in the future with the respective challenge so we can try it ourselves.

  • @VivekChavan-ov3pl
    @VivekChavan-ov3pl Před 11 měsíci +1

    Hey keep doing this challenges Atleast one a week

  • @asagiai4965
    @asagiai4965 Před 11 měsíci +1

    I think this is a nice thought process.
    BTW if you don't technically care about how the sliding would work. You can maybe use jquery slide
    I forgot the method but it have to do with slide
    Then you just pass the element you want to slide. Or the className

  • @alixaprodev
    @alixaprodev Před 11 měsíci

    please create a video on that transition part as well. i mean css transition. it woulb be great

  • @ayushgogna9732
    @ayushgogna9732 Před 11 měsíci

    u can use framer motion sliding stuff it gets real easy

  • @balduin_b4334
    @balduin_b4334 Před 11 měsíci

    making a slide animation is such a pain, I did it once with headlessui Transitions, rendering prevElement, current and nextElement. it was so inconsistent, that we decided to just fade in n out :D

    • @WebDevCody
      @WebDevCody  Před 11 měsíci +1

      Yeah I’ve tried it and it wasn’t easy. Definitely isn’t a beginner friendly challenge

  • @talhaibnemahmud
    @talhaibnemahmud Před 11 měsíci +2

    After calling clearInterval you're not actually clearing the ref.
    You should probably set
    interval.current = null;

  • @programmers_sanctuary
    @programmers_sanctuary Před 11 měsíci

    oooo, using a ref for other stuff besides elements do not occur to me (I don't read all the docs hahaha). Awesome!

  • @Anonymousssss368
    @Anonymousssss368 Před 11 měsíci

    Hey can you make a vedio on firebase serverside pagination using next 13 server actions ?

  • @tit162-tiwarianurag2
    @tit162-tiwarianurag2 Před 11 měsíci

    I want more

  • @alasassi5889
    @alasassi5889 Před 11 měsíci

    Is AI going to replace us what do you think. Can you make a video about it?

  • @anubhavbansal8922
    @anubhavbansal8922 Před 7 měsíci

    where can i get the starter code ?

    • @WebDevCody
      @WebDevCody  Před 7 měsíci

      just setup a vite app and choose ts react

    • @anubhavbansal8922
      @anubhavbansal8922 Před 7 měsíci +1

      @@WebDevCody i was looking for something from where you had started images buttons are already there

  • @sparda111222
    @sparda111222 Před 10 měsíci

    Why do cut so much of your screen?

    • @WebDevCody
      @WebDevCody  Před 10 měsíci +1

      I’m on a mac book air, and it doesn’t do 1080p

  • @nark4837
    @nark4837 Před 11 měsíci +1

    I would have personally created a function for `changeSlide` like so:
    function changeSlide(amount: -1 | 1) {
    setSlideIndex(slideIdx => (slideIdx + amount) % SLIDES.length)
    }

    • @brandonsayring
      @brandonsayring Před 11 měsíci

      This is a clean solution!
      In the slide index setter, you'd want to add SLIDES.length to the first operand in parenthesis. This is so that in the case where slideIdx is 0 and the amount arg is -1, you're not trying to return the remainder of -1 % SLIDES.length
      eg.
      setSlideIndex(slideIdx => (SLIDES.length + slideIdx + amount) % SLIDES.length)

    • @nark4837
      @nark4837 Před 10 měsíci

      Nice improvement!
      I am anything but a JavaScript developer, so I did not know that modulo is not well-defined for negative numbers in JavaScript, unlike other languages (e.g., Python).
      @@brandonsayring

  • @alasassi5889
    @alasassi5889 Před 11 měsíci

    What is the point od dedicating my time and energy for something AI can do easily and better than me

    • @WebDevCody
      @WebDevCody  Před 11 měsíci +1

      Ai gets the code wrong a lot, I use gpt a lot, and often it fails me