Advertisement
Guest User

Untitled

a guest
Jul 4th, 2023
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { ReactNode } from "react";
  2.  
  3.  
  4. type Properties = Readonly<{
  5.   requiredPropertyExample: string;
  6.   optionalPropertyExample?: string;
  7. }>;
  8.  
  9. export class Sample extends React.Component<Properties> {
  10.  
  11.   public static readonly defaultProps: Required<Pick<Properties, "optionalPropertyExample">> = {
  12.     optionalPropertyExample: "DEFAULT"
  13.   };
  14.  
  15.  
  16.   private method1(): ReactNode {
  17.     const optionalPropertyExample: string = this.props.optionalPropertyExample;
  18.     console.log(optionalPropertyExample);
  19.     // ...
  20.   }
  21.  
  22.   private method2(): ReactNode {
  23.     const optionalPropertyExample: string = this.props.optionalPropertyExample ?? Sample.defaultProps.optionalPropertyExample;
  24.     // ...
  25.   }
  26.  
  27.   //
  28.  
  29.   private methodN(): ReactNode {
  30.     const optionalPropertyExample: string = this.props.optionalPropertyExample ?? Sample.defaultProps.optionalPropertyExample;
  31.     // ...
  32.   }
  33.  
  34.  
  35.   public render(): ReactNode {
  36.  
  37.     const optionalPropertyExample: string = this.props.optionalPropertyExample ?? Sample.defaultProps.optionalPropertyExample;
  38.  
  39.   }
  40.  
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement