React - Props


props is the only object argument passed to a component

Props is similar to State, but it is public and not fully controlled by the component.


in React - JSX

<MyComponent name={javascriptVariable} color="Blue"/>

will create two props

  • and props.color



  • must be named from the component's own point of view rather than the context in which it is being used.
  • are read-only. A component must never modify its own props. It must modify it via this.setState() <note important>All React components must act like pure functions with respect to their props.</note> See React - State


Default value

Default values are defined by assigning to the special defaultProps property to the component.

class Greeting extends React.Component {
  render() {
    return (
      <h1>Hello, {}</h1>
  • Specifies the default value for the name prop:
Greeting.defaultProps = {
  name: 'Stranger (Default)'
  • And render
  <Greeting />,
<div id="root">
<!-- called the "root" DOM node because everything inside it will be managed by React DOM -->

Type checking

built-in Type checking in React is known as prop-types


With the chrome plugin

Documentation / Reference

Powered by ComboStrap