Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { ReactNode } from "react";
- type Properties = Readonly<{
- requiredPropertyExample: string;
- optionalPropertyExample?: string;
- }>;
- export class Sample extends React.Component<Properties> {
- public static readonly defaultProps: Required<Pick<Properties, "optionalPropertyExample">> = {
- optionalPropertyExample: "DEFAULT"
- };
- private method1(): ReactNode {
- const optionalPropertyExample: string = this.props.optionalPropertyExample;
- console.log(optionalPropertyExample);
- // ...
- }
- private method2(): ReactNode {
- const optionalPropertyExample: string = this.props.optionalPropertyExample ?? Sample.defaultProps.optionalPropertyExample;
- // ...
- }
- //
- private methodN(): ReactNode {
- const optionalPropertyExample: string = this.props.optionalPropertyExample ?? Sample.defaultProps.optionalPropertyExample;
- // ...
- }
- public render(): ReactNode {
- const optionalPropertyExample: string = this.props.optionalPropertyExample ?? Sample.defaultProps.optionalPropertyExample;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement