【发布时间】:2018-04-25 07:05:28
【问题描述】:
我正在使用查询选项为我的查询传递动态变量,但似乎如果我设置defaultProps,graphql 无法获取道具值。
我的代码如下:
Page.defaultProps = {
startDate: moment().hour(15).toISOString(),
endDate: moment().add(1).hour(3).toISOString(),
};
export default compose(graphql(myQuery, { options: (props: IPageProps) => ({ variables: { range: { start: props.startDate, end: props.endDate }}}))(Page);
注销props表明组件加载时defaultProps需要时间才能真正包含进来,变量总是会变成{ startDate: undefined, endDate: undefined }
有没有更好的处理方法?
【问题讨论】: