Here is another fun beginner React challenge (image slider)

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

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

  • @alexandrepereira6522
    @alexandrepereira6522 Год назад +7

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

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

    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

  • @vivianliu5011
    @vivianliu5011 8 месяцев назад +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.

  • @talhaibnemahmud
    @talhaibnemahmud Год назад +2

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

  • @auditusich
    @auditusich Год назад +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.

  • @iamsomraj
    @iamsomraj Год назад +3

    Love these type of videos! Keep them coming 🔥

  • @FacundoTroitero
    @FacundoTroitero 8 месяцев назад

    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"!

  • @cod-the-creator
    @cod-the-creator Год назад +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  Год назад

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

  • @youmnaification
    @youmnaification 10 месяцев назад

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

  • @VivekChavan-ov3pl
    @VivekChavan-ov3pl Год назад +1

    Hey keep doing this challenges Atleast one a week

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

    Thanks for react videos

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

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

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

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

    • @WebDevCody
      @WebDevCody  Год назад +1

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

  • @tit162-tiwarianurag2
    @tit162-tiwarianurag2 Год назад

    I want more

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

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

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

    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

  • @siya.abc123
    @siya.abc123 Год назад

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

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

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

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

    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.

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

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

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

    u can use framer motion sliding stuff it gets real easy

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

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

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

    Why do cut so much of your screen?

    • @WebDevCody
      @WebDevCody  Год назад +1

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

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

    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

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

    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  Год назад +1

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

  • @anubhavbansal8922
    @anubhavbansal8922 9 месяцев назад

    where can i get the starter code ?

    • @WebDevCody
      @WebDevCody  9 месяцев назад

      just setup a vite app and choose ts react

    • @anubhavbansal8922
      @anubhavbansal8922 9 месяцев назад +1

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

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

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

  • @Sky-yy
    @Sky-yy Год назад

    Yooo , back at it

  • @nark4837
    @nark4837 Год назад +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 Год назад

      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 Год назад

      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