Skip to main content

React image component width

Comments

5 comments

  • Eyal Katz Talmon

    Hey Yarden,

    Notice that though the Client Hints solution seems to be the easiest and intuitive way to go, it is currently partly restricted by Google (due to privacy concerns), and works only on the mobile version of Chrome. More information regarding Client Hints and Cloudinary can be found here.

    Therefore it is currently recommended to use our JavaScript solution for responsive images.

    Do you aim at delivering the images on mobile Chrome only? Have you tested this code on mobile Chrome?

    Thanks,

    Eyal

    0
  • yarden

    Hey,
    Thanks for the answer, but I can't seem to figure out how to use the sdk with react.
    Do you happen have any small example projects maybe?

    I've installed the package and imported it into the component.
    In the component I've set:

    let cl=newcloudinary.Cloudinary({cloud_name:"my-cloud-name", secure:true});
     
    cl.responsive();
     
    and then:
    <sectionclassName="header-container">
    <img
    className="cld-responsive"/>
    </section>
     
    When checking the console, I see there is no src attribute. What is the right way to integrate it with react?
    Thanks
    0
  • Eyal Katz Talmon

    Following is a simple example of achieving responsive images behavior (after installing the React SDK - following the integration steps provided here) -

    First import the relevant components -
    import {Image, Transformation} from 'cloudinary-react';
     
    Then rendering the image -
    render() {
       return (
          <div>
             <Image cloudName="<cloud_name>" dpr="auto" responsive width="auto" crop="scale" publicId="sample">
               <Transformation effect="cartoonify"/>
             </Image>
          </div>
       );
    }
     
    More information about using Cloudinary and responsive images can be found here and here.
     
    Hope this helps! let me know if you have any further questions.
    0
  • yarden

    Hey,
    Thanks for the example.
    The problem was the dpr. When I set it to auto, for some reason my laptop was detected to 2, that is why the url was fetching such a huge image. I removed the dpr attribute and now it works very well.

    Thanks a lot for the help!

    0
  • Eyal Katz Talmon

    Sure! Glad it worked out.

    0

Post is closed for comments.