O'Reilly logo

React and React Native - Second Edition by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheriting properties

Inheriting properties works by defining the default property values and the property types as static attributes of a base class. Any classes that inherit from this base class also inherit the property values and the property specs. Let's take a look at a base class implementation:

import { Component } from 'react';import PropTypes from 'prop-types';export default class BaseComponent extends Component {  // The specifiction for these base properties.  static propTypes = {    users: PropTypes.array.isRequired,    groups: PropTypes.array.isRequired  };  // The default values of these base properties.  static defaultProps = {    users: [],    groups: []  };  render() {    return null;  }} 

The class itself doesn't actually do anything. The only ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required