Why does the following doing the following:
type Props = {
name?: string
age: number
}
const Test = FC<Props> = (props) => {
return (
<h1>Hello, {props.name}. You are {props.age} years old.</h1>
)
}
Test.defaultProps = {
name: "John"
}
Give off the warning that name could be undefined when strict mode is set to true even though name is defined in defaultProps.
namecan be undefined inProps?if not ask me i have a solutionPropsinsideFCwas that you could do that...namehas a default value. But if you remove the?it will ask for thenameprop every time you use the component, which is invalid, as it has a default property.namecan be undefined, therefor the code should consider it. You can remove the optional mark (?) because you know that name is never undefined.