-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swiper with React 18 causes TypeError: Cannot read properties of undefined (reading 'slideClass') #5613
Comments
I Guess It was caused by React Strict Mode |
Due to React18, there was a problem that you could not specify className for SwiperSlide. To avoid that I downgraded to React 17. |
Hello @cizz3007. Please provide a online reproduction by codesandbox or a minimal GitHub repository. You can fork one of our demos in codesandbox to get start. Issues labeled by |
Due to React18, there was a problem that you could not specify className for SwiperSlide. |
I'm having this issue when used with nextjs but just tried to replicate with a basic example on codepen and I'm not getting the error, so there must be something else in my setup causing it. https://codesandbox.io/s/swiper-default-react-forked-3y14np |
Running into this issue as well with Next.js 12.1.5 + React 18.0.0; at one point @Muhammad-Zeshan-Tufail's workaround seems to work; if the I'll try to create codesandbox reproduction; @nolimits4web what's your preferred workflow for issues that were closed with the |
@raphaelsaunier better create a new one |
You are right. I just deleted React.StrictMode and it's working |
Upgrading to ^8.2.2 seemed to fix it for me without needing to switch strict mode to false |
To solve this problem, you need to update swiper to latest version. try this command to update your swiper to latest version.
or
I hope it can help you. |
Latest swiper don't work for me. "next": "13.1.5",
"react": "18.2.0",
"react-dom": "18.2.0",
- "swiper": "9.0.2",
+ "swiper": "8.4.7", |
how did you install "swiper": "8.4.7" with yarn? |
It's still there on |
@mahadidev could you elaborate more what should be replaced when using nextjs image component? |
@diginikkari what he means is to use the standard img html element instead of the Image from next.js. I did this and I think as of today is the best solution |
I have updated my comment. please check it out. |
@dertuman The latest version worked without using a regular img HTML element |
Okay I'll give it a shot! Ty. |
I also had the problem with wrapperClass, and by updating swiper to the latest version, my problem was solved |
I really don't think removing the Image Next componet is a good approach since it'll remove it's image optimization features, downgrading swiper to 8.4.7 worked for me as well, even made me able to use the loop={true} prop with no problems! |
In my case downgrading it to 8.4.7 just caused different error of |
Still relevant! onSwiper={(swiper) => {
const el = swiper.el
el.addEventListener('mouseenter', () => {
swiper.autoplay.stop()
})
el.addEventListener('mouseleave', () => {
swiper.autoplay.start()
})
}} Error: |
Check that this is really a bug
Reproduction link
none
Bug description
TypeError: Cannot read properties of undefined (reading 'slideClass')
Expected Behavior
No response
Actual Behavior
Swiper version
8.0.7
Platform/Target and Browser Versions
macOs Chrome latest
Validations
Would you like to open a PR for this bug?
The text was updated successfully, but these errors were encountered: