Wie definiere ich defaultProps für eine zustandslose Reaktionskomponente in typescript?
Ich möchte @ definierdefaultprops
für meine reine Funktionskomponente, aber ich erhalte einen Tippfehler:
export interface PageProps extends React.HTMLProps<HTMLDivElement> {
toolbarItem?: JSX.Element;
title?: string;
}
const Page = (props: PageProps) => (
<div className="row">
<Paper className="col-xs-12 col-sm-offset-1 col-sm-10" zDepth={1}>
<AppBar
title={props.title}
zDepth={0}
style={{ backgroundColor: "white" }}
showMenuIconButton={false}
iconElementRight={props.toolbarItem}
/>
{props.children}
</Paper>
</div>
);
Page.defaultProps = {
toolbarItem: null,
};
Ich weiß, dass ich das schreiben kann:
(Page as any).defaultProps = {
toolbarItem: null,
};
Gibt es eine bessere Möglichkeit, @ hinzuzufügedefaultProps
?