docs: remove this usage from function component (#29596)

Fix a small error in the `next/script` docs.

Let me know if you'd like a `useState` for the sake of a complete example.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
This commit is contained in:
Arthur Denner 2021-10-04 14:02:57 +02:00 committed by GitHub
parent c06a3c1731
commit 1c1929b3a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -109,16 +109,19 @@ export default function Home() {
### Executing Code After Loading (`onLoad`)
```js
import { useState } from 'react'
import Script from 'next/script'
export default function Home() {
const [stripe, setStripe] = useState(null)
return (
<>
<Script
id="stripe-js"
src="https://js.stripe.com/v3/"
onLoad={() => {
this.setState({ stripe: window.Stripe('pk_test_12345') })
setStripe({ stripe: window.Stripe('pk_test_12345') })
}}
/>
</>