Typescript 在react native中扩展通用道具
抱歉,如果标题有误导性。我似乎找不到合适的头衔。 我有两门课Typescript 在react native中扩展通用道具,typescript,react-native,react-navigation,Typescript,React Native,React Navigation,抱歉,如果标题有误导性。我似乎找不到合适的头衔。 我有两门课 ****************Form.tsx interface Props{} interface State{} class Form extends Component<Props, State>{ protected submit(){ // contains a code when form submits } } ****************Login.tsx clas
****************Form.tsx
interface Props{}
interface State{}
class Form extends Component<Props, State>{
protected submit(){
// contains a code when form submits
}
}
****************Login.tsx
class LoginForm extends Form{
render(){
return(
<View>
<Button onClick = {() => this.props.navigation.goBack()}
<Button onClick= {() => this.submit()} />
</View>
);
}
}
***************Form.tsx
接口道具{}
界面状态{}
类形式扩展组件{
受保护的提交(){
//表单提交时包含代码
}
}
****************Login.tsx
类LoginForm扩展了表单{
render(){
返回(
this.props.navigation.goBack()}
this.submit()}/>
);
}
}
我想这么做
<LoginForm navigation = {someObject} />
<LoginForm navigation = {someObject} />
但我不能这样做,因为我似乎找不到解决办法。我只是想知道如何将更多的道具传递给LoginForm。我找到了一个解决方案,但它只有在表单始终被扩展且不作为组件使用时才会起作用。在我的示例中,我从未打算将表单用作组件。因此,如果有帮助,这里有一个解决方案
***********Form.tsx
interface State{}
class Form<P= {}> extends Component<P, State>{
}
***********Login.tsx
interface LoginFormProps{
navigation: SomeObjectType
}
class Login extends Form<LoginFormProps>{
}
**********Form.tsx
界面状态{}
类形式扩展组件{
}
***********Login.tsx
接口LoginFormProps{
导航:SomeObjectType
}
类登录扩展表单{
}
然后我就可以做了