react-bits:数组作为子元素

前端之家收集整理的这篇文章主要介绍了react-bits:数组作为子元素前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

react-bits
原文

数组作为子元素很常见

// We use map() to create an array of React Elements for every value in the array.
(<ul>
  {["first","second"].map((item) => (
    <li>{item}</li>
  ))}
</ul>)
 //That’s equivalent to providing a literal array.
(<ul>
  {[
    <li>first</li>,<li>second</li>
  ]}
</ul>)
 // This pattern can be combined with destructuring,JSX Spread Attributes,and other components,for some serIoUs terseness.
(<ul>
  {arrayOfMessageObjects.map(({ id,...message }) =>
    <Message key={id} {...message} />
  )}
</ul>)
原文链接:https://www.f2er.com/react/304348.html

猜你在找的React相关文章