Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

javascript - Can I store images in const variables in React

I am trying to shift all the images which I have on local-storage to cloudinary. I don't want to change the sass settings and just want to use the image. I am trying something like this.

const collaborate = () => {
  return(
    <Image 
      cloudName="my-id"
      publicId="publicc-id"
      dpr="auto"
      responsive
      width="auto"
      crop="scale"
      responsiveUseBreakpoints="true">
    </Image>
  )
}

And in the same file

const Highlights = () => {
  return (
    <section className="Highlights">
      {/* Collaborate */}
      <Highlight
        containerClass="highlight-collaborate"
        title="Collaborate"
        description={descriptions[1]}
        linkUrl="/about"
        linkText="See What We Do"
        image={collaborate}
        imageAlt="Collaborate"
        backgroundColor="#EEFFF0"
      />

    </section>
  );
};

The image is working when I try using // import collaborate from '../../../assets/file_name'; but when I am trying it this way then I am getting the imageAlt and not the image, any idea how can I resolve this ?

question from:https://stackoverflow.com/questions/65839731/can-i-store-images-in-const-variables-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...