gokcan/react-shimmer

How to add `alt` to <Image> component

Giggiux opened this issue · 5 comments

for SEO optimization the image's alt tag is needed.

It would be optimal to have it on the Image component.

You may use the NativeImgProps prop to pass alt to the underlying <img>.

You may use the NativeImgProps prop to pass alt to the underlying <img>.

can you give example how to use NativeImgProps

@arifals27 I haven't used this in 2 years now, but I guess you may just do something like <Image NativeImgProps={{alt:"my alt text"}}>

here is the line that adds that NativeImgProps to the Image props

gokcan commented

Example usage:

import React from 'react'
import { Image, Breathing } from 'react-shimmer'

function App() {
  return (
    <div>
      <Image
        src='https://source.unsplash.com/random/800x600'
        fallback={<Breathing width={800} height={600} />}
        NativeImgProps={{ alt: "Descriptive text." }}
      />
    </div>
  )
}

Hey thank you for this wonderful package, but i have a question regarding alt text. I am using it the same way as you mentioned but the alt text is not visible.
alttext

in browser it is visible something like this

alttext2