Javascript 如何使用connect、createReduxForm和typescript将道具传递到HOC?
如何使用connect、createReduxForm和typescript将道具传递到react功能组件中 我混合使用了redux表单和打字脚本。我有一个子组件,我正试图将道具传递给它,但我一直收到一个类型错误,没有找到解决方法。这是代码 生日页面.tsxJavascript 如何使用connect、createReduxForm和typescript将道具传递到HOC?,javascript,angular,reactjs,typescript,redux-form,Javascript,Angular,Reactjs,Typescript,Redux Form,如何使用connect、createReduxForm和typescript将道具传递到react功能组件中 我混合使用了redux表单和打字脚本。我有一个子组件,我正试图将道具传递给它,但我一直收到一个类型错误,没有找到解决方法。这是代码 生日页面.tsx interface propsInterface { match?: any; } const BirthdayPage = ({ match: { params } }: propsInterface) => { cons
interface propsInterface {
match?: any;
}
const BirthdayPage = ({ match: { params } }: propsInterface) => {
const userId = params.id;
return (
<AppWrapper
>
<MyBirthdayForm userId={userId} />
</AppWrapper>
);
};
export default BirthdayPage;
接口propsInterface{
匹配?:任何;
}
常量生日页=({match:{params}}:propsInterface)=>{
const userId=params.id;
返回(
);
};
导出默认生日页面;
MyBirthdayForm.tsx
interface propsInterface {
saveMyBirthday?: any;
userId?: string
}
function onSubmit() {
console.log('toot toot');
}
const MyBirthdayForm = ({
saveMyBirthday,
userId
}: propsInterface) => {
const token = userId == 'selectedUser';
return (
<>
<Typography variant='h1'>
{token}
</Typography>
<form
onSubmit={handleSubmit(onSubmit)}
>
<BirthdayForm token={token} />
<AppButtons
onSubmit={handleSubmit(onSubmit)}
rightButtonText={'Submit'}
/>
</form>
</>
);
};
interface propsMatchInterface {
saveMyBirthday: any;
}
const mapDispatchToProps: propsMatchInterface = {
saveMyBirthday,
};
const createReduxForm: any = reduxForm({
form: 'test'
});
export default connect<any>(
null,
mapDispatchToProps,
)(createReduxForm(MyBirthdayForm));
接口propsInterface{
保存我的生日?:任何;
用户ID?:字符串
}
函数onSubmit(){
console.log('toot-toot');
}
常量MyBirthdayForm=({
祝我生日快乐,
用户ID
}:propsInterface)=>{
const-token=userId==“selectedUser”;
返回(
{token}
);
};
界面支撑界面{
保存我的生日:任何;
}
const mapDispatchToProps:PropsMachinterFace={
祝我生日快乐,
};
const createReduxForm:any=reduxForm({
表格:'测试'
});
导出默认连接(
无效的
mapDispatchToProps,
)(createReduxForm(MyBirthdayForm));
为什么我一直收到这个错误
Type '{ userId: any; }' is not assignable to type '(IntrinsicAttributes & Pick<unknown, never>) | (IntrinsicAttributes & Pick<Pick<unknown, never>, never> & Pick<InferProps<unknown>, never>) | (IntrinsicAttributes & ... 2 more ... & Partial<...>) | (IntrinsicAttributes & ... 2 more ... & Partial<...>)'.
Property 'userId' does not exist on type '(IntrinsicAttributes & Pick<unknown, never>) | (IntrinsicAttributes & Pick<Pick<unknown, never>, never> & Pick<InferProps<unknown>, never>) | (IntrinsicAttributes & ... 2 more ... & Partial<...>) | (IntrinsicAttributes & ... 2 more ... & Partial<...>)
Type“{userId:any;}”不可分配给Type'(intrinsitattributes&Pick)|(intrinsitattributes&Pick&Pick)|(intrinsitattributes&…2 more…&Partial)|(intrinsitattributes&…2 more…&Partial)|。
属性“userId”不存在于类型“(IntrinsityAttributes&Pick)|(IntrinsityAttributes&Pick&Pick)|(IntrinsityAttributes&…2更多…&部分)|(IntrinsityAttributes&…2更多…&部分)