`Cannot convert undefined or null to object` when using `Thumbs` module
See original GitHub issueCheck that this is really a bug
- I confirm
Reproduction link
https://github.com/bnn1/swiper-issue
Bug description
When creating component from example in React app, app throws runtime error TypeError: Cannot convert undefined or null to object
.
Reproduction link contains next.js app but it is possible to reproduce with pure react bootstrapped with CRA
Steps to reproduce:
- Create react app
yarn create react-app
- Install
swiper
- Create component
Carousel
and add the following code
code
import React, { useState } from "react";
import { Swiper, SwiperSlide } from "swiper/react";
import { Thumbs } from "swiper";
import "swiper/css";
export const Component = () => {
// store thumbs swiper instance
const [thumbsSwiper, setThumbsSwiper] = useState(null);
return (
<main>
{/* Main Swiper -> pass thumbs swiper instance */}
<h1>hello</h1>
<Swiper modules={[Thumbs]} thumbs={{ swiper: thumbsSwiper || null }}>
<SwiperSlide>1</SwiperSlide>
<SwiperSlide>2</SwiperSlide>
<SwiperSlide>3</SwiperSlide>
<SwiperSlide>4</SwiperSlide>
<SwiperSlide>5</SwiperSlide>
</Swiper>
{/* Thumbs Swiper -> store swiper instance */}
{/* It is also required to set watchSlidesProgress prop */}
<Swiper modules={[Thumbs]} watchSlidesProgress onSwiper={setThumbsSwiper}>
{/* ... */} <SwiperSlide>1</SwiperSlide>
<SwiperSlide>2</SwiperSlide>
<SwiperSlide>3</SwiperSlide>
<SwiperSlide>4</SwiperSlide>
<SwiperSlide>5</SwiperSlide>
</Swiper>
</main>
);
};
import { Component } from './Component';
function App() {
return (
<div className="App">
<Component />
</div>
);
}
export default App;
- Run application
yarn start
- Navigate to
localhost:3000
- Open dev tools
Expected Behavior
No errors occur during runtime
Actual Behavior
Errors occur during runtime
Swiper version
8.1.0
Platform/Target and Browser Versions
Linux (arch), Chrome Version 100.0.4896.88 (Official Build) (64-bit)
Validations
- Follow our Code of Conduct
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
- Make sure this is a Swiper issue and not a framework-specific issue
Would you like to open a PR for this bug?
- I’m willing to open a PR
Issue Analytics
- State:
- Created a year ago
- Reactions:12
- Comments:15
Top Results From Across the Web
Swiper React cannot convert undefined or null to object
I tried using onSwiper prop to achieve this functionality but i ran into an error. thumbs.js:67 Uncaught TypeError: Cannot convert undefined or ...
Read more >Cannot convert undefined or null to Object in JavaScript
The "Cannot convert undefined or null to Object" error occurs when we pass a null or an undefined value to a function that...
Read more >Cannot convert undefined or null to object ( But we didn't ...
Hi Retool team, Since this morning, we have this error message that appears (Cannot convert undefined or null to object).
Read more >Cannot convert undefined or null to object - Code Grepper
I had this issue when compiling using my global truffle module. i switched to npx truffle compile after installing it as a dev...
Read more >npm err! cannot convert undefined or null to object - You.com
Since you updated the weback cli version you probably had to update something else for it to work properly but you did not,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
the workaround is
thumbs={{ swiper: thumbsSwiper }}
replace tothumbs={{ swiper: thumbsSwiper && !thumbsSwiper.destroyed ? thumbsSwiper : null }}
I am facing with this issue as well with Nextjs 12 + React 18