Comments (13)
Hello, I hope to help you. It worked like this for me:
import the two css files into _app.js
It would look like this:
import App from "next/app";
import "owl.carousel/dist/assets/owl.carousel.css";
import "owl.carousel/dist/assets/owl.theme.default.css";
class MyApp extends App {
render() {
const { Component, pageProps } = this.props;
return (
<Component {...pageProps} />
)}};
export default MyApp;
In next.config.js add
const withPlugins = require("next-compose-plugins");
const withImages = require("next-images");
const webpack = require("webpack");
module.exports = withPlugins([withImages], {
webpack: (config) => {
config.node = {
fs: "empty",
};
config.module.rules.push({
test: /\.(glb|gltf|bin)$/,
use: {
loader: "file-loader",
},
});
config.plugins.push(
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
}));
return config;
},
});
PD: The important thing here is to configure webpack with jquery
In the file where they use the OwlCarousel. In my case in Testimonials.js
import React from "react";
import dynamic from "next/dynamic";
const OwlCarousel = dynamic(import("react-owl-carousel"), {
ssr: false,
});
function Testimonials() {
return (
<OwlCarousel className="owl-theme" loop margin={10} nav>
...
</OwlCarousel>
)}
`
from react-owl-carousel.
@nayyir-haulerads thank you ! I'm using nextjs and I imported owlcarousel like this ;
import dynamic from 'next/dynamic';
const OwlCarousel = dynamic(import('react-owl-carousel'));
then in my main component;
state= { display:false};
componentDidMount(){ this.setState({display:true}) }
and finally returned like that ;
<div className="container slider-container">
{this.state.display ? <MyOwl/> : <div></div>}
</div>
first components mounts and sets state to true .then next/dynamic loads owl-carousel library and it works.
from react-owl-carousel.
Hi @rh0delta , I tried everything possible. It has to do with style-loader webpack uses and the library. The library exposes the "window" object which the server-side does not have, so when it tries to preload the page on the server the app crashes, because the object does not exist.
I found a alternative, which does Exactly the same thing and works perfectly, except a very small bug, which isn't really a bug. (last link)
react-slick:
https://github.com/akiran/react-slick
If you decide to use custom arrow components, just create your component as below:
akiran/react-slick#671
from react-owl-carousel.
Were you able to determine the cause of this issue because I am now receiving the same error.
from react-owl-carousel.
I was able to get around the web pack errors with using the cdns for owl carousel, and using componentDidMount to initialize carousel object.
from react-owl-carousel.
Unfortunately, I have the same issue with my server-side rendering.
I will use alternative slider, but I would be happy if this issue will be fixed, because I like owl-carousel.
from react-owl-carousel.
Hi @valeriashpiner, if you just include the original cdns for owl carousel 2 and initialize the carousel for your objects using ReactDOM to find the element within componentDidMount it will work
from react-owl-carousel.
Isn't there any solution yet ? @nayyir-haulerads can you be more specific and give some details please ? @valeriashpiner what "alternative slider" you used ?
from react-owl-carousel.
@ibrhmvci the solution that I have found, and continue to use, is to load the owl carousel library from its cdn, rather than using the node package. After loading the cdn you will have access to the owlCarousel function globally. Whichever component you decide to use to render the carousel be sure to add a βrefβ attribute to carousel component and call owlCarousel on the element within componentDidMount().
from react-owl-carousel.
Hope that helps
from react-owl-carousel.
Hi @nayyir-haulerads, can you show your solution in code?
from react-owl-carousel.
Can anyone tell me the solution ?
TIA
from react-owl-carousel.
Can anyone share their solution? I'd really appreciate
from react-owl-carousel.
Related Issues (20)
- How to filter? HOT 1
- Not able to update state variable on onChanged callback , gives error 'unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering' HOT 1
- Add Typescript support
- index.js:1 Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code.
- UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. | Please update the following components: ReactOwlCarousel HOT 9
- window is not defined HOT 1
- SlideTransition prop doesn't exist in react
- Bank white page issue HOT 2
- autoHeightClass doesnt work
- react-owl-carousel mobile issue - one slide getting place at the top of the another slide at arr HOT 1
- i can't use methods HOT 1
- carousel installed but not working
- nav button is not working for scrolling card
- navContainer not working
- jQuery cannot see $
- dotData not working
- Blank OwlCarousel : items moved from .owl-stage to .owl-carousel when resize the window mobile
- Warning: Invalid DOM property `class`. Did you mean `className` HOT 1
- UNSAFE_componentWillReceiveProps HOT 6
- Fails to install in React 17 HOT 3
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 react-owl-carousel.