79335000

Date: 2025-01-07 05:58:09
Score: 1
Natty:
Report link

You can do it simply without dealing with Typescript Interfaces, just while defining the function that is going to accept those props using '?' operator as follows

const ChildComponent: React.FC<{ firstName: string, lastName?: string}> = ({ fName, lName }) => {

}

Calling child component with LastName

<ChildComponent firstName={"John"} lastName={"Doe"}/>  

Calling child component without LastName

<ChildComponent firstName={"John"}/>  

Happy Coding! 🖤🐳

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Mohammad Bilal