Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

【超初心者】Reactで配列の値を.map()で展開する書き方

More than 3 years have passed since last update.

このページを参考に配列の値をpropsとしてそれを.map()で展開する書き方をまとめました。
http://basic-react.axlight.com/html/lesson-07.html

環境

  • Babel
  • React
  • ReactDOM

書いてみた

HTML
<div id="app"></div>
React
const items = [
  { name: 'AAA', color: 'black'},
  { name: 'BBB', color: 'blue'},
  { name: 'CCC', color: 'orange'},
  { name: 'DDD', color: 'green'},
];

const Hello = ({name, color}) => (
  <div>
    <p style={{ color }}>Hello {name}!</p>
  </div>
);

const App = () => (
  <div>
    {items.map((item) => (
      <Hello name={item.name} color={item.color} />
     ))}
  </div>
);

const render = ReactDOM.render(<App />, document.getElementById('app'));
render();

まだまだ勉強不足

macotok
React好き
access
SDNからセンサ、家電、電子書籍まで。ACCESSはあらゆるレイヤのデバイス、サービスを「繋げて」いきます。
http://jp.access-company.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away