ES6 and React.js: Pass props to components using comment-like code
Comments usually help you, but they can lie. Sometimes that lie will lead you down a wild goose chase to find something that doesn't exist. The JavaScript engine cannot validate comments so they have to always be taken at face value. Use them only when you need to. Luckily, ES6 brings some nice features to cleanly avoid comments when passing props into components. Let's look at a small example. Not all of data in our ParentComponent gets passed into UserProfile, its child component. But at the same time, we want to make our code as readable and expressive as possible. There are multiple ways to approach this. import React, { Component } from 'react' // ParentComponent props // this.props = { // name: 'Andrew', // description: 'A person', // imageUrl: 'http://www.somewebsite.com/profile_picture.jpg', // age: 26, // height: '180cm', // birthday: '10.18.1990', // favoriteColor: 'blue', //...