Skip to content

Commit

Permalink
feat: react forward ref (#31)
Browse files Browse the repository at this point in the history
* feat: foward ref

* chore: changeset

* Update clever-baboons-hunt.md

---------

Co-authored-by: Phumrapee Limpianchop <[email protected]>
  • Loading branch information
peam1146 and rayriffy authored Oct 24, 2024
1 parent 9dcb2aa commit 2f9c97b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-baboons-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@urami/react": patch
---

update image component to foward ref
9 changes: 5 additions & 4 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultLoader, buildSource } from '@urami/utils'

import type { FunctionComponent, ImgHTMLAttributes } from 'react'
import { forwardRef, type ImgHTMLAttributes } from 'react'
import type { Loader } from '@urami/types'

export interface ImageProps extends ImgHTMLAttributes<HTMLImageElement> {
Expand All @@ -10,24 +10,25 @@ export interface ImageProps extends ImgHTMLAttributes<HTMLImageElement> {
loader?: Loader
}

const Image: FunctionComponent<ImageProps> = ({
const Image = forwardRef<HTMLImageElement, ImageProps>(({
src,
width,
quality = 75,
loader = defaultLoader,
...rest
}) => {
},ref) => {
const builtProps = buildSource(loader, src, width, quality)

return (
<img
ref={ref}
src={builtProps.src}
srcSet={builtProps.srcSet}
decoding="async"
loading="lazy"
{...rest}
/>
)
}
})

export default Image

0 comments on commit 2f9c97b

Please sign in to comment.