LoginSignup
3
2

More than 5 years have passed since last update.

備忘録 React でのリストの作り方

Last updated at Posted at 2017-05-19

react でのリストの作り方

list.jsx

const NavList = (data) => {
  <ul>
  { data.map((element) => {
     <li>
       <div>装飾的な何か</div>
       <Link to={data.link}>{data.name}</Link>
     </li>
  })}
  </ul>
}

こんな感じで初期は書いていた
でも、mapに無名関数を渡しているので毎回作成されるのでよろしくない

リファクタ後


const NavLink = (element) => {
  <li>
    <div>装飾的な何か</div>
    <Link to={element.link}>{element.name}</Link>
  </li>
}

const NavList = (data) => {
  <ul>
    { data.map(NavLink) }
  </ul>
}

こっちの方が見やすいし呼ばれるのは一度だけなので配列で作成する時はこうしようという備忘録

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2