【发布时间】:2019-04-24 07:34:21
【问题描述】:
我正在使用 Recompose 来定义一些方法,如下所示:
export interface WithStateProps {
isDisabled: boolean;
isReady: boolean;
setDisabled(value: boolean): void;
setReady(value: boolean): void;
}
export const withStateHoc = withState('isDisabled', 'setDisabled', false);
export const withIsEligibleStateHoc = withState(
'isReady',
'setReady',
true
);
export const isReady = (value : string) => {
return value ? true : false
};
export type WrappedProps = StepContentProps &
FormikProps<MyAddress> &
InjectedIntlProps &
AddressFormHandlers & WithStateProps;
当我想使用 setReady 方法时,我收到这条消息:props.setReady is not a function 这是我的代码:
export const withFormikHoc = withFormik<
WrappedProps & RouteComponentProps<{}> & InjectedIntlProps & WithStateProps,
MyAddress
>({
handleSubmit: async (values, { props, setSubmitting }) => {
const addressAlreadyVerified = isReady(values.country);
if(addressAlreadyVerified) {
props.setReady(true)
}
}
})
当我在 VCode 中将鼠标悬停在 props.setReady(true) 上时,我可以看到:(method) WithStateProps.setReady(value: boolean): void
但我知道props.setReady不是函数!
有人知道我在这里缺少什么吗?
【问题讨论】:
-
在您使用
withFormikHoc的地方添加您的setReady -
已经通过添加添加:WrappedProps
标签: javascript reactjs typescript recompose