JavaScript
Default Prop Values in React

by Benny Neugebauer

import React from 'react';

class List extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <ol>
        {this.props.items.map((item, index) => <ListItem key={index} text={item}/>)}
      </ol>
    );
  }
}

List.defaultProps = {
  items: []
};

import React from 'react';

const List = ({items = []}) => {
  return (
    <ol>
      {items.map((item, index) => <ListItem key={index} text={item}/>)}
    </ol>
  );
};