mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Closes: #30962 This PR adds a new `onReady` prop to `next/script` to handle shortcomings of the current `onLoad` prop. Some third-party providers and widgets require initialization code to run after the script's `load` event and every time the component is mounted. The `onReady` should solve that use case. For more details, refer to the discussion in #30962. CC @janicklas-ralph ## Bug - [X] Related issues linked using `fixes #number` - [X] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: JJ Kasper <[email protected]>
25 lines
544 B
JavaScript
25 lines
544 B
JavaScript
import Script from 'next/script'
|
|
import Link from 'next/link'
|
|
|
|
const url =
|
|
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js'
|
|
|
|
const Page = () => {
|
|
return (
|
|
<div class="container">
|
|
<Link href="/page9">Page 9</Link>
|
|
<div id="text"></div>
|
|
<Script
|
|
src={url}
|
|
id="script1"
|
|
onReady={() => {
|
|
// eslint-disable-next-line no-undef
|
|
document.getElementById('text').textContent += _.repeat('a', 3)
|
|
}}
|
|
></Script>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Page
|