Props and PropTypes
The components that we've seen so far are completely static in that they take no external input and always render exactly the same. This isn't especially interesting because the same outcome can be achieved by writing plain old HTML. However, React provides a mechanism for making components dynamic by using properties, or props.
Accepting props
Props are passed into a component in order to modify their base definition. Let's take another look at our Title
component:
import React, { Component } from 'react'; export default class Title extends Component { render() { return ( <h1> Hello World! </h1> ); } }
While the title of a single article might be Hello World!
, this component needs to be more dynamic if it is to be reused within ...
Get Mastering React Native now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.