GithubHelp home page GithubHelp logo

Comments (5)

davidjerleke avatar davidjerleke commented on June 10, 2024 1

Hi @ranno-lauri,

Thanks for the bug report. If you're unsure something is a bug or not, you can create a discussion instead. To answer your question, there's a gotcha with the init event and embla-carousel-react. Please read this to understand it:

As far as I can see, all other events are working as expected in your CodeSandbox. For example, if I drag the carousel and wait for it to stop, it will fire the settle event.

Best,
David

from embla-carousel.

ranno-lauri avatar ranno-lauri commented on June 10, 2024 1

Hey @davidjerleke,

Thank you for the reply and suggestions. Tried it out and works as expected. Problem solved! Should this be included as 'gotcha' in the documentation?

from embla-carousel.

ranno-lauri avatar ranno-lauri commented on June 10, 2024 1

Indeed, caused quite a bit of confusion. That's the general emotion with useEffect and React 18 has just made it worse 😆. Using useEffect instead of 'init' would be habitual for React devs. To make migrations from React 17 -> 18 easier for others, would still be useful to have the information in the documents, but add a deprecation note to the 'init' method (both in docs and in code), so new implemenations would not use it.

from embla-carousel.

davidjerleke avatar davidjerleke commented on June 10, 2024

@ranno-lauri thanks for confirming.

Should this be included as 'gotcha' in the documentation?

I'm not sure which solution would be optimal. I've been considering removing the init event because it feels like it has been causing more confusion than anything else 😅. For example, when using Vanilla JS, you can just run any code after invoking the EmblaCarousel() constructor and the carousel will be ready. So the init event might be redundant:

// Vanilla JS
import EmblaCarousel from 'embla-carousel'

const emblaNode = document.querySelector('.embla')
const emblaApi = EmblaCarousel(emblaNode)

console.log('INIT - Embla is ready')
// instead of emblaApi.on('init', () => { console.log('INIT - Embla is ready') })

// React JS
import useEmblaCarousel from 'embla-carousel-react'

export function EmblaCarousel() {
  const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true })

  useEffect(() => {
    if (!emblaApi) return
    
    console.log('INIT - Embla is ready')
  }, [emblaApi])
  // ...
}

What's your thoughts about this?

Best,
David

from embla-carousel.

davidjerleke avatar davidjerleke commented on June 10, 2024

Thanks for your input @ranno-lauri!

from embla-carousel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.