Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to set the width and height to 100% of the container that the Image is in? #59

Closed
AizenSousuke opened this issue May 24, 2020 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@AizenSousuke
Copy link

<Image src={${
props.imageLink ??
"http://loremflickr.com/480/272/default"
}} alt="button" fallback={<Shimmer width={100%} height={100%} />} />

@AizenSousuke AizenSousuke changed the title Anyway to set the width and height to 100% of the container that the Image is in? Any way to set the width and height to 100% of the container that the Image is in? May 24, 2020
@gokcan gokcan added the duplicate This issue or pull request already exists label May 24, 2020
@gokcan
Copy link
Owner

gokcan commented May 24, 2020

Hey @AizenSousuke,

You'll need to pass actual width and height in pixels if you want to use <Shimmer /> as a fallback.

This lib is quite useful for achieving what you want to achieve. An implementation like below should work:

import React from 'react'
import Image, { Shimmer } from 'react-shimmer
import ContainerDimensions from 'react-container-dimensions'

export const App = ({ src }) => (
    <div>
        <ContainerDimensions>
           {({ width, height }) => 
            <Image
             src={src}
             fallback={<Shimmer width={width} height={height} />}
            />
           }
        </ContainerDimensions>
    <div>
)

@AizenSousuke
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants
@AizenSousuke @gokcan and others