MathieuBMS
8/17/2019 - 4:47 PM

Looping in JSX

It's common to use array.map(fn) to output loops in JSX.

class Message extends React.Component {
    render() {
        const msgs = [
            {id: 1, text: "Greetings!"},
            {id: 2, text: "Goodbye!"},
        ];

        return (
            <ul>
                {msgs.map(m => <li>{m.text}</li>)}
            </ul>
        )
    }
}