JavaScript React Basics (retired) Thinking in Components Loops and Lists in JSX

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,647 Points

Some questions about React propTypes

Looking at this piece of code:

  propTypes: {
    title: React.PropTypes.string,
    initialPlayers: React.PropTypes.arrayOf(React.PropTypes.shape({
      id: React.PropTypes.number.isRequired,
      name: React.PropTypes.string.isRequired,
      score: React.PropTypes.number.isRequired

Is this about avoiding bugs from the developer or validating user input? Is this comparable to the Angular people bringing TypeScript into Angular 2?

2 Answers

Jeremy Castanza
Jeremy Castanza
12,075 Points

My take on this is that Javascript is trying to become a more mature language. Other programming languages typically include datatypes when defining variables. Vanilla Javascript doesn't really enforce datatypes or give you meaningful errors when issues related to datatype occur in your program.

29,441 Points

It's more like TypeScript. It's for developers to have indication what data component expects and other developers (or you from the future) should pass into it.