Comments (5)
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.
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.
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.
@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.
Thanks for your input @ranno-lauri!
from embla-carousel.
Related Issues (20)
- [Bug]: Angular autoplay error HOT 1
- [Bug]: Autoplay fast scroll when opened in a new tab HOT 7
- [Bug]: no specific name for plugin import, have to use "index" instead HOT 4
- [Bug]: Embla Carousel's animation becomes less smooth when the battery saving mode is enabled. HOT 1
- [Bug]: Render when slides are wider than view size HOT 5
- [Bug]: When using the wheel gesture to swipe the carousel, for the first slide and the last slide, there are excessive blank space. HOT 2
- [Bug]: Thumbnails example won't work in RTL HOT 2
- [Bug]: Height is getting set to 0 HOT 4
- [Bug]: Scroll broken after direction update HOT 15
- [Bug]: Jest testing bug return TypeError: undefined is not a function HOT 2
- [Bug]: Bad scroll progress reporting when loop = true HOT 1
- [Bug]: beforeUnmount destroys too soon during Vue transitions HOT 10
- [Bug]: Fade example missing dependency and missing vanilla examples HOT 10
- [Bug]: Image disperses after window resize HOT 1
- [Bug]: Fade plugin has wrong peer dependency version
- [Bug]: any type for `Autoplay` plugin options HOT 5
- [Bug]: iOS Stutter HOT 5
- [Bug]: Video with controls in slide interferes with swiping HOT 1
- [Bug]: Trailing spaces HOT 1
- [Bug]: verticle view slider - last slider is not appearing above first slider by default HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embla-carousel.