mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 12:11:20 -08:00
26 lines
555 B
JavaScript
26 lines
555 B
JavaScript
import { useEffect, useRef } from "react";
|
|
import Artplayer from "artplayer";
|
|
|
|
export default function ArtplayerReact({ option, getInstance, ...rest }) {
|
|
const artRef = useRef();
|
|
|
|
useEffect(() => {
|
|
const art = new Artplayer({
|
|
...option,
|
|
container: artRef.current,
|
|
});
|
|
|
|
if (getInstance && typeof getInstance === "function") {
|
|
getInstance(art);
|
|
}
|
|
|
|
return () => {
|
|
if (art && art.destroy) {
|
|
art.destroy(false);
|
|
}
|
|
};
|
|
}, [option, getInstance]);
|
|
|
|
return <div ref={artRef} {...rest}></div>;
|
|
}
|