You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// OR operatornull|number// Mandatory Parameter
prop1 : String// Optional Parameter
prop1 ?: String// Data TypesStringBooleanNumber// Integer or Double// React// Functional ComponentexportconstComponentName: React.FC<Props>=()=>{
...
}// Interface for PropsinterfaceProps{prop1: String;// Mandatory Prop (Only Colon)prop2?: Boolean// Optional Prop (Question Mark + Colon)}// Inteface for JS ObjectinterfacePerson{firstName: StringlastName: String}
Defining a React Functional Component
importReactfrom'react';interfaceProps{prop1: String;// Mandatory Prop (Only Colon)prop2?: Boolean// Optional Prop (Question Mark + Colon)}// Define the type of each JS variable after the colon// In this case It's a React Function Component// Also Pass an interface defining the type of Props that the function needsexportconstComponentName: React.FC<Props>=()=>{return(<div><input/></div>)}
Interfaces
// Types of Declarations in a TS interfaceinterfaceProps{text: String;ok: Boolean;i: Number;// An integer or a doublefn: (x: String)=>void;// A function returning nothingfn2: (j: Number)=>String;// A function returning Stringobj: {f1: String};// An Object}