19
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Organization

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

このページを参考に配列の値を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();

まだまだ勉強不足

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
Sign upLogin
19
Help us understand the problem. What are the problem?