I'm dynamically importing @vimeo/player in useEffect but when setting up Player I'm getting Uncaught (in promise) TypeError: You must pass either a valid element or a valid id. which comes from this part in the Vimeo script:
if (!isDomElement(element)) {
throw new TypeError('You must pass either a valid element or a valid id.');
} } // Already initialized an embed in this div, so grab the iframe
So I guess the new Player constructor is called twice for some reason?
This error does not appear when I use a normal import - even though it seems setup is called twice no matter if dynamic import or not so I'm a bit confused why this error only appears with the dynamic import.
I tried adding a cleanup function but that also doesn't help - grateful for any pointers!
useEffect(() => {
let isSetup = false;
async function setup() {
if (!isSetup) {
const { default: Player } = await import('@vimeo/player');
playerRef.current = new Player(
playerRef.current,
playerConfig,
);
isSetup = true;
playerRef.current.on('loaded', () => setIsLoading(false));
}
}
if (playerRef.current) {
setup();
}
return () => {
isSetup = false;
playerRef.current.destroy();
};
}, [playerRef]);