This website collects cookies to deliver better user experience
import React from 'react'; import { Child } from './Child'; type Props = { greeting: string; firstName: string; lastName: string; }; export const Parent: React.FC<Props> = ({ greeting, firstName, lastName }) => { return ( <> <span> {greeting}</span> <Child firstName={firstName} lastName={lastName} /> </> ); };
import React from 'react'; type Props = { firstName: string; lastName: string; }; export const Child: React.FC<Props> = ({ firstName, lastName }) => { return ( <> <div>{firstName}</div> <div>{lastName}</div> </> ); };
firstName
lastName
If one part changes we need to make sure the others stays in sync.
If the Child component is used in a similar pattern elsewhere we need to make sure we update the props there too.
import React, { ComponentProps } from 'react'; import { Child } from './Child'; type Props = ComponentProps<typeof Child> & { greeting: string; }; export const Parent: React.FC<Props> = ({ greeting, ...childProps }) => { return ( <> <span> {greeting}</span> <Child {...childProps} /> </> ); };
#coding #softwareengineering #productivity #webdeveloper #cleancode #codingtips #javascript #webdev #devlife #programming #computerscience
38
0