Home >Web Front-end >JS Tutorial >How to loop map in react

How to loop map in react

藏色散人
藏色散人Original
2021-01-11 09:38:213360browse

The method of react looping map: first open the corresponding code file; then add a key as a unique identifier to the child element; and finally use map to traverse.

How to loop map in react

The operating environment of this tutorial: windows7 system, react17.0.1 version, Dell G3 computer.

Recommended: react video tutorial

Map traversal in react

<ul id="ul_rwardList">
    {
        this.state.reward.map(function (item) {
            return (
                <li className="db vh" key={item.id}>
                    <div className="fx1">{item.num}</div>
                    <div className="fx1">{item.username}</div>
                    <div className="fx1 text-right">{item.rward_time}</div>
                </li>
            )})
    }
</ul>

tips: When using map traversal, you need to give Add a key to the child element as a unique identifier, and the key values ​​must be consecutive

The above is the detailed content of How to loop map in react. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn