-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.jsx
More file actions
32 lines (30 loc) · 904 Bytes
/
Copy pathindex.jsx
File metadata and controls
32 lines (30 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import Swiper from 'swiper';
import createHash from './hash.js';
import 'swiper/dist/css/swiper.min.css';
class ReactAwesomeSwiper extends React.Component {
constructor(...params) {
super(...params);
this.id = `swiper${createHash(16)}`;
this.swiper = null;
}
componentDidMount() {
this.swiper = new Swiper(`#${this.id}`, this.props.config);
}
componentDidUpdate() {
this.swiper.destroy();
this.swiper = new Swiper(`#${this.id}`, this.props.config);
}
componentWillUnmount() {
this.swiper.destroy();
}
render() {
const { config, className, ...rest } = this.props;
return (
<div id={this.id} className={`swiper-container ${className}`} {...rest}>
{this.props.children}
</div>
);
}
}
export default ReactAwesomeSwiper;