diff --git a/docs/integrations/react.md b/docs/integrations/react.md index 8671a0f..20be83e 100644 --- a/docs/integrations/react.md +++ b/docs/integrations/react.md @@ -26,9 +26,9 @@ import { LazyImage } from '@unlazy/react' export default function MyComponent() { return ( ) } @@ -52,18 +52,22 @@ The `LazyImage` component accepts the following props: In both examples, the `sizes` attribute is automatically calculated. -```html - - - - - +```tsx +return ( + <> + {/* Blurhash in `blurhash` attribute */} + + + {/* Encoded image in `src` attribute */} + + +) ``` diff --git a/packages/react/playground/App.tsx b/packages/react/playground/App.tsx index 6548430..2a5a3f7 100644 --- a/packages/react/playground/App.tsx +++ b/packages/react/playground/App.tsx @@ -6,8 +6,8 @@ function App() {
diff --git a/packages/react/playground/package.json b/packages/react/playground/package.json index f746c22..6f106b0 100644 --- a/packages/react/playground/package.json +++ b/packages/react/playground/package.json @@ -1,9 +1,9 @@ { - "private": true, - "type": "module", - "scripts": { - "dev": "vite", - "build": "vite build", - "preview": "vite preview" - } + "type": "module", + "private": true, + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" } +} diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx index c0501c7..e9b411b 100644 --- a/packages/react/src/index.tsx +++ b/packages/react/src/index.tsx @@ -1,14 +1,21 @@ -import React, { useEffect, useRef } from 'react' +import { useEffect, useRef } from 'react' import type { ImgHTMLAttributes } from 'react' import { lazyLoad } from 'unlazy' import type { UnLazyLoadOptions } from 'unlazy' -interface Props extends ImgHTMLAttributes, Pick { +interface Props + extends ImgHTMLAttributes, + Pick { autoSizes?: boolean blurhash?: string } -export function LazyImage({ autoSizes, blurhash, blurhashSize }: Props) { +export function LazyImage({ + autoSizes, + blurhash, + blurhashSize, + ...rest +}: Props) { const target = useRef(null) useEffect(() => { @@ -21,13 +28,14 @@ export function LazyImage({ autoSizes, blurhash, blurhashSize }: Props) { cleanup() } } - }, []) + }, [blurhash, blurhashSize]) return ( ) }