Update Artplayer.js

This commit is contained in:
Harvey Zack committed 2022-05-03 10:20:51 +08:00
1 parent 9b723947e6
commit 8fa763b9c7
1 file changed
+15 -25
+15 -25
View File
@@ -1,36 +1,26 @@
import React from 'react'; // eslint-disable-next-line no-unused-vars
import React, { useEffect, useRef } from 'react';
import Artplayer from 'artplayer'; import Artplayer from 'artplayer';
export default class ArtplayerReact extends React.Component { export default function ({ option, getInstance, ...rest }) {
constructor(props) { const artRef = useRef();
super(props);
this.instance = null;
this.artRef = React.createRef();
}
componentDidMount() { useEffect(() => {
const { option, getInstance } = this.props; const art = new Artplayer({
this.instance = new Artplayer({
...option, ...option,
container: this.artRef.current, container: artRef.current,
}); });
if (getInstance && typeof getInstance === 'function') { if (getInstance && typeof getInstance === 'function') {
getInstance(this.instance); getInstance(art);
} }
}
componentWillUnmount() { return () => {
if (this.instance && this.instance.destroy) { if (art && art.destroy) {
this.instance.destroy(); art.destroy(false);
} }
} };
}, [option, getInstance]);
render() { return <div ref={artRef} {...rest}></div>;
const { option, getInstance, ...rest } = this.props;
return React.createElement('div', {
ref: this.artRef,
...rest,
});
}
} }