如果我在我的项目中使用typescript,是否会使React中的prop-types的使用过时?对于prop-types,我将不得不经历定义类型的咕噜声,但是使用typescript,这一步将被否定。我的想法是正确的吗?
听起来很对。使用TypeScript时,您可以通过界面定义道具。
interface ButtonProps {
text: string,
shadow?: boolean
}
const Button: React.FunctionComponent<ButtonProps> = props => {
return ( /* [...] */ );
};
见here
如果你使用打字,我认为你不需要道具类型。 Typescript是强类型的好解决方案,但为此您需要编写更多代码。 Props Types为您的类或功能组件提供高效的典型化和小代码块