React Holiday

A Special Array-ngment

When I first saw React, it wasn’t the JSX that threw me. It was this line:

let listItems = items.map((item) => <li>{item}</li>);

What was this magic that turned an array into React elements? Had it existed in JavaScript all this time? Why had I never seen it or used it? How is it different that forEach()?

My brain was exploding with questions about arrays.

React ❤️ Arrays

Arrays are used everywhere in React.

We use arrays to generate lists, create Fragments, consume Hooks… they’re even automatically underastood as component children!

Array mastery can help you just about everywhere in React.

Question

How many Array methods are you familiar with — 0, 1, 20?

I’m not sure I couldn’t confidently use more than 3 but MDN says there are 36. 36!

Check out this MDN page on Array and read up on a method you didn’t know before. How could it have helped you in a previous task?