Skip to content

Instantly share code, notes, and snippets.

@edoves
Last active November 22, 2024 08:06
Show Gist options
  • Save edoves/36dbc14215f19ec24e15bf9805736b6d to your computer and use it in GitHub Desktop.
Save edoves/36dbc14215f19ec24e15bf9805736b6d to your computer and use it in GitHub Desktop.

Example of using forward ref

What we trying to achieve here is that when we use the logo component we stil get the classes of tailwind if dont do the forwardRef the component does not know or do auto suggest classes

/logo.tsx

type ImgProps = React.ImgHTMLAttributes<HTMLImageElement> & {
  imgSrc: string
}

export default React.forwardRef<HTMLImageElement, ImgProps>(
  ({ className, imgSrc, ...props }, ref) => {
    return <img src={imgSrc} className={className} ref={ref} {...props} />
  }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment