next.js 13 with swiper slider #43755
Replies: 9 comments 16 replies
-
You can refer to the docs: https://beta.nextjs.org/docs/rendering/server-and-client-components#third-party-packages |
Beta Was this translation helpful? Give feedback.
-
For me, it is solved by changing:
[Next 13.3.0] [App Directory] ['use client'] |
Beta Was this translation helpful? Give feedback.
-
try adding these lines:
|
Beta Was this translation helpful? Give feedback.
-
i got this issue the moment i implemented swiperjs into a nextjs project. You're importing a component that needs useRef. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
10 | * Released on: July 8, 2023 Maybe one of these should be marked as a client entry with "use client": |
Beta Was this translation helpful? Give feedback.
-
ok i managed to solve it by by adding "use client" in the first line of code. |
Beta Was this translation helpful? Give feedback.
-
Add "use client;" to the top of the component where you are using Swiper. My setup with Next 13 and Swiper 10.3.1:
Also created a repository. Can be used as a starter. |
Beta Was this translation helpful? Give feedback.
-
I think this course can help you if you are Persian. this is a course about sliders in next js . |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same problem at the moment, but I'm using page route, seems no solution found at the moment |
Beta Was this translation helpful? Give feedback.
-
Just a bit shame that I have to ask the AI aka copilot, here is the solution copilot give me, that's work on nextjs page route.
|
Beta Was this translation helpful? Give feedback.
-
Verify canary release
Provide environment information
hi, in next 12, next and swiper slider works together. but in next 13, we have a problem. because of swiper slider needs context in it's structure, it need to be a client component and "use client", but we cann't add "use client" in the structure of swiper.js.
what is the solution?
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
nothing-in-github
To Reproduce
swiper slider needs to be a client component.
Describe the Bug
./node_modules/swiper/react/context.js
You're importing a component that needs createContext. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default.
,----
1 | import { createContext, useContext } from 'react';
: ^^^^^^^^^^^^^
`----
Maybe one of these should be marked as a client entry with "use client":
node_modules\swiper\react\context.js
node_modules\swiper\react\swiper-react.js
components\cart\index.jsx
app\page.jsx
Expected Behavior
go to top:)
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Beta Was this translation helpful? Give feedback.
All reactions