我喜欢按以下方式编写默认道具:
interface IMyFunction {
p1?: string;
p2: string;
}
const MyFunction = (props: IMyFunction) => {
const defaultProps: Required<IMyFunction> = {
p1: "v1",
...props,
};
...
}
我知道MyFunction.defaultProps已被弃用,现在需要使用默认参数,所以我使用它们,但使用我的方法,我将它们合并到常量中,defaultProps
因为我发现它更方便。这种方法有什么我没有看到的问题吗,还是我应该以标准方式使用默认参数?