gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
trying to load a image: const image = ${process.env.PUBLIC_URL}/img/agency-04a.png;…
- User
trying to load a image:
const image = `${process.env.PUBLIC_URL}/img/agency-04a.png`; return ( <section id="contact" class="mb-4"> <div class="card"> <img src={{ `${backgroundImage}` }} class="card-img-top" alt="Header Image">react
- Assistant
It looks like you're trying to load an image in React, but there are a couple of syntax issues in your code. Your current usage of the
srcattribute is incorrect. In JSX, you should use curly braces{}to embed JavaScript expressions.Here's a corrected version of your code:
const image = `${process.env.PUBLIC_URL}/img/agency-04a.png`; return ( <section id="contact" className="mb-4"> <div className="card"> <img src={image} className="card-img-top" alt="Header Image" /> </div> </section> );Key Changes:
-
Curly Braces for
src:- Change
src={{${backgroundImage}}}tosrc={image}. This correctly embeds the JavaScript expression that represents the image path.
- Change
-
classNameInstead ofclass:- In JSX, use
classNameinstead ofclassfor defining CSS classes.
- In JSX, use
Now, when you use
image, it will reference the correct path to your image, which is built using the environment variable. Make sure the image path resolves correctly to where the image is stored in your project for it to load properly. -