E
E
embiid2019-02-23 20:51:08
WordPress
embiid, 2019-02-23 20:51:08

How to give a property to an image in ReactDOM?

How to set a property for the image to the component, just like he gave the name property.

<script type="text/babel">
            var TeamCard = React.createClass({
                render: function () {
                    return  (
                        <article class="open hidden">
                            <img class="article-img" src="svg/charlotte-hornets.svg" alt={this.props.name} />
                                <h1 class="article-title">
                                    <a href="">{this.props.name}</a>
                                </h1>
                        </article>
                    )
                }
            })

            ReactDOM.render(
                <div>
                    <TeamCard image-path="svg/charlotte-hornets.svg" name="Charlotte Hornets"/>
                    <TeamCard image-path="svg/charlotte-hornets.svg" name="Charlotte Hornets"/>
                </div>,
                document.getElementById("cards")
            )
        </script>

PS I'm sorry for such a description of the question, I don't know how to paraphrase correctly)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iBird Rose, 2016-09-17
@iiiBird

such a decision would be a crutch. since right now you have done - the most normal option. so it's better not to. and so you can write a script to have a modal. and when you click on the pictures - this modal opens and these pictures are appended there

V
Vladimir Proskurin, 2019-02-23
@embiid

Also, just don't separate property names with hyphens or underscores.

<script type="text/babel">
            var TeamCard = React.createClass({
                render: function () {
                    return  (
                        <article className="open hidden">
                            <img className="article-img" src={this.props.imagePath} alt={this.props.name} />
                                <h1 className="article-title">
                                    <a href="">{this.props.name}</a>
                                </h1>
                        </article>
                    )
                }
            })

            ReactDOM.render(
                <div>
                    <TeamCard imagePath="svg/charlotte-hornets.svg" name="Charlotte Hornets"/>
                    <TeamCard imagePath="svg/charlotte-hornets.svg" name="Charlotte Hornets"/>
                </div>,
                document.getElementById("cards")
            )
        </script>

PS: write className instead of class, this is a feature of jsx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question