-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Clappr example in api docs * Fix Clappr Demo
- Loading branch information
1 parent
f76062b
commit 6dd55d3
Showing
7 changed files
with
111 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,3 @@ | |
height: 411px; | ||
} | ||
} | ||
|
||
#clappr-player { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEffect } from "react"; | ||
|
||
const loadScript = (url: string): Promise<HTMLScriptElement> => { | ||
return new Promise((resolve, reject) => { | ||
const script = document.createElement("script"); | ||
script.src = url; | ||
script.async = true; | ||
script.type = "text/javascript"; | ||
script.onload = () => resolve(script); | ||
script.onerror = (error) => reject(error); | ||
document.body.appendChild(script); | ||
}); | ||
}; | ||
export const useScripts = (scripts: string[]) => { | ||
useEffect(() => { | ||
let isCleanup = false; | ||
|
||
const loadAllScripts = async () => { | ||
for (const script of scripts) { | ||
await loadScript(script); | ||
if (isCleanup) break; | ||
} | ||
}; | ||
|
||
void loadAllScripts(); | ||
|
||
return () => { | ||
isCleanup = true; | ||
scripts.forEach((url) => { | ||
const scriptElement = document.querySelector(`script[src="${url}"]`); | ||
if (scriptElement) { | ||
document.body.removeChild(scriptElement); | ||
} | ||
}); | ||
}; | ||
}, [scripts]); | ||
}; |