Unverified Commit b760c8dd authored by Dueen Eduarda's avatar Dueen Eduarda Committed by GitHub

docs(image): Use hook inside of function component (#40096)

The example broke the [Rules of Hooks](https://reactjs.org/warnings/invalid-hook-call-warning.html#:~:text=Hooks%20can%20only%20be%20called%20inside%20the%20body%20of%20a%20function%20component.) by calling the hook outside of the function component.
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 1bf2ab6a
...@@ -279,14 +279,16 @@ The Ref must point to a DOM element or a React component that [forwards the Ref] ...@@ -279,14 +279,16 @@ The Ref must point to a DOM element or a React component that [forwards the Ref]
import Image from 'next/image' import Image from 'next/image'
import React from 'react' import React from 'react'
const lazyRoot = React.useRef(null) const Example = () => {
const lazyRoot = React.useRef(null)
const Example = () => ( return (
<div ref={lazyRoot} style={{ overflowX: 'scroll', width: '500px' }}> <div ref={lazyRoot} style={{ overflowX: 'scroll', width: '500px' }}>
<Image lazyRoot={lazyRoot} src="/one.jpg" width="500" height="500" /> <Image lazyRoot={lazyRoot} src="/one.jpg" width="500" height="500" />
<Image lazyRoot={lazyRoot} src="/two.jpg" width="500" height="500" /> <Image lazyRoot={lazyRoot} src="/two.jpg" width="500" height="500" />
</div> </div>
) )
}
``` ```
**Example pointing to a React component** **Example pointing to a React component**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment