November 2018
Beginner
502 pages
10h 22m
English
Default values can be added to component props when the component is initialized. These can be implemented using a static object literal called defaultProps.
Let's make use of this feature in our Confirm component, as follows:
class Confirm extends React.Component<IProps> { public static defaultProps = { cancelCaption: "Cancel", okCaption: "Okay" }; public render() { ... }}
If we look at our running app again, we have button captions once more.
<Confirm title="React and TypeScript" content="Are you sure you want to ...
Read now
Unlock full access