mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
c09e29c040
[web] Payment page stories GitOrigin-RevId: 9f8aff0cf839bc811d8612e97bd627b577860cc8
31 lines
643 B
TypeScript
31 lines
643 B
TypeScript
import { useState, useEffect } from 'react'
|
|
|
|
type ExternalScriptLoaderProps = {
|
|
children: JSX.Element
|
|
src: string
|
|
}
|
|
|
|
function ExternalScriptLoader({ children, src }: ExternalScriptLoaderProps) {
|
|
const [loaded, setLoaded] = useState(false)
|
|
|
|
useEffect(() => {
|
|
const body = document.querySelector('body')
|
|
const script = document.createElement('script')
|
|
|
|
script.async = true
|
|
script.src = src
|
|
script.onload = () => {
|
|
setLoaded(true)
|
|
}
|
|
|
|
body?.appendChild(script)
|
|
|
|
return () => {
|
|
body?.removeChild(script)
|
|
}
|
|
}, [src])
|
|
|
|
return loaded ? children : null
|
|
}
|
|
|
|
export default ExternalScriptLoader
|