16
TypeScriptのReactコンポーネントクラスにdefaultProps
を定義する例は誰でも表示できますか?TypeScriptを使用してReactコンポーネントクラスにdefaultPropsを宣言する方法は?
interface IProps {}
interface IState {}
class SomeComponent extends Component<IProps, IState> {
// ... defaultProps ?
// public defaultProps: IProps = {}; // This statement produces an error
constructor(props: IProps) {
super(props);
}
// ...
}
TypeScriptを使用する場合は、セミコロンの直前に 'as IProps'を追加して、オブジェクトをIPropsにキャストする必要があります。 –
提供されたリンクでは、 'defaultProps'については説明しません。代わりに、https://facebook.github.io/react/docs/react-component.html#defaultprops – WoodenKitty
Thanks @WoodenKittyを参照して、しばらくの間、ドキュメントを探してみてください。 Googleは役に立たなかった –