【发布时间】:2017-01-21 01:56:30
【问题描述】:
我想为我的纯函数组件定义defaultprops,但我得到一个类型错误:
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,
};
我知道我可以这样写:
(Page as any).defaultProps = {
toolbarItem: null,
};
有没有更好的方法添加defaultProps?
【问题讨论】:
标签: reactjs typescript