添加react组件

This commit is contained in:
Harvey Zack committed 2019-04-15 13:16:15 +08:00
1 parent f13aebd720
commit e00fab0bfe
6 files changed
+129

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import React, { Component } from 'react';
import Artplayer from 'artplayer';
export default class ArtplayerComponent extends Component {
constructor(props) {
super(props);
Artplayer.utils.errorHandle(
props.option && typeof props.option === 'object',
"The prop 'option' object cannot be missing",
);
this.instance = null;
this.artRef = React.createRef();
}
componentDidMount() {
const { option, getInstance } = this.props;
this.instance = new Artplayer({
...option,
container: this.artRef,
});
if (getInstance && typeof getInstance === 'function') {
getInstance(this.instance);
}
}
componentWillUnmount() {
if (this.instance && this.instance.destroy) {
this.instance.destroy();
}
}
render() {
const { option, getInstance, ...rest } = this.props;
return <div ref={this.artRef} {...rest} />;
}
}