E
E
embiid2019-07-16 11:53:55
JavaScript
embiid, 2019-07-16 11:53:55

How to display img in component props?

There is a component which is used many times. It has text and photos. I understood the text, but not the picture.
The code of the component itself:

function NewSubProject(props) {
    return (
        <div className="gallery-image">
            <div className="img-box">
                <img src = { props.ProjectView } />
                <div className="transparent-box">
                    <div className="caption">
                        <p> { props.ProjectName } </p>
                        <p className="opacity-low"> { props.ProjectDesc } </p>
                    </div>
                </div>
            </div>
        </div>
    )
}

export default NewSubProject;

This is how I call it:
<NewSubProject  ProjectView = {'http://via.placeholder.com/350x250.png'}
                                ProjectName = "asd"
                                ProjectDesc = "123" />

But, the problem is that I want to upload a picture to him not from the Internet, but from a folder that is in src. Here is how I tried to do it:
<NewSubProject  ProjectView = {'require("../images/github-brands.svg")'}
 ...

This method only worked with the tag

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-16
@embiid

props is usually called in camelCase. Instead of ProjectView, the property should be called projectView or generally shortened to view (or img).

<NewSubProject img={require('../images/github-brands.svg')}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question