我的拥有
import { NextPage } from 'next';
import React from 'react';
interface Props {
name: string;
gretting?: string; // Error: ESLint: propType "gretting" is not required, but has no corresponding defaultProps declaration.(react/require-default-props)
}
const Hello: React.FunctionComponent<Props> = ({ name, gretting = 'night' }: Props) =>
<p>Hi {name} Good {gretting}</p>;
const Home: NextPage = () => <Hello name="Jhon Doe" />;
export default Home;
问题
Eslint react 插件报出以下错误:ESLint: propType "gretting" is not required, but has no corresponding defaultProps declaration.(react/require-default-props)
。
根据这个答案,使用默认参数值的 defaultProps 方法是可行的,那么解决这个问题的最佳方法是什么?使用 Hello.defaultProps = {}
或关闭规则 react/require-default-props
? 还有更好的方法吗?
nombre, saludo
,但被解构为name, greeting
。这段代码真的是你所拥有的吗?因为它不会起作用。 - Alex Wayne