【发布时间】:2019-12-15 16:44:51
【问题描述】:
在我的 React Native 编写的 TypeScript 中,我使用了 ReactNavigation。在我使用下面的类组件之前
class HomeScreen extends Component {
static navigationOptions: any;
...
}
// in navigation config
HomeScreen.navigationOptions = {...}
有了 hooks 支持,我将 HomeScreen 迁移到如下功能组件
function HomeScreen(props:Props) {
return (...)
}
HomeScreen.navigationOptions = {...} // VS Code error here
问题是我错过了static navigationOptions: anypropery/method,并得到了错误 [In VS Code]
'navigationOptions' 不存在于类型'(props: Props) => Element'
有没有办法在函数组件中拥有静态属性/方法?或者有什么解决方法?
【问题讨论】:
-
你的打字稿版本是什么?
-
我使用的是 TS v 3.3
-
reactandtypescript.dev/examples/…希望对您有所帮助!
标签: reactjs react-native react-navigation