typescript - 在本机反应中扩展通用道具
问题描述
抱歉,如果标题具有误导性。我似乎找不到合适的标题。我有两个班。
****************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>
);
}
}
我想做这个
<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>{
}
然后我可以做
<LoginForm navigation = {someObject} />
推荐阅读
- php - 如何为多个 PHP 版本配置 PHP 扩展?
- java - 通过 testNG 运行课程时自动装配的替代方法是什么?
- c++ - 为什么 CMake 的“ExternalProject_Add”命令不构建这个 autotools 库?
- python - 每次按下按钮时,如何更改 tkinter 代码以随机绘制?
- face-api - 如何使用 face-api.js 检测活人脸而不是照片?
- .net - 使用 XPathCompiler 引用用户定义的 xsl:function
- c# - C# libreoffice 基本连接
- html - 在 Django 中访问模型属性
- python - 使用列表时,Tkinter 按钮只能工作一次
- gnome-shell - 如何通过命令行启动 gnome 的内置屏幕录像机?