Skip to content

Commit

Permalink
Update script.md (#39400)
Browse files Browse the repository at this point in the history
Adding `strategy="lazyOnload"` for prevent minor confusion.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
sanjaiyan-dev and ijjk committed Aug 8, 2022
1 parent 9f8713f commit 1cc6e47
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docs/basic-features/script.md
Expand Up @@ -240,6 +240,7 @@ Or by using the `dangerouslySetInnerHTML` property:
```jsx
<Script
id="show-banner"
strategy="lazyOnload"
dangerouslySetInnerHTML={{
__html: `document.getElementById('banner').classList.remove('hidden')`,
}}
Expand Down Expand Up @@ -280,16 +281,19 @@ export default function Home() {
Some third-party scripts require users to run JavaScript code after the script has finished loading and every time the component is mounted (after a route navigation for example). You can execute code after the script's `load` event when it first loads and then after every subsequent component re-mount using the `onReady` property:

```jsx
import { useRef } from 'react'
import Script from 'next/script'

export default function Home() {
const mapRef = useRef()
return (
<>
<div ref={mapRef}></div>
<Script
id="google-maps"
src="https://maps.googleapis.com/maps/api/js"
onReady={() => {
new google.maps.Map(ref.current, {
new google.maps.Map(mapRef.current, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
})
Expand Down

0 comments on commit 1cc6e47

Please sign in to comment.