javascript – 如何使用Flow定义反应导航的道具
作者:互联网
我正在研究一个简单的React Native App,并决定使用反应导航.我还决定使用Flow进行静态类型检查.我无法弄清楚的是,如何用Flow定义与导航相关的道具.
例如我将我的App.js定义为使用StackNavigator,如下所示:
import StackNavigator from 'react-navigation';
import Main from './app/containers/Main';
const App = StackNavigator({
Main: { screen: Main },
});
export default App;
然后我定义我的Main类,但我不知道如何在我的道具中引用react-navigation:
// @flow
import React, { Component } from 'react';
import { View, Text } from 'react-native';
type Props = {
navigate: ????
};
type State = {};
class Main extends Component<Props, State> {
...
}
解决方法:
根据https://github.com/react-navigation/react-navigation/issues/3643
import { NavigationState, NavigationScreenProp } from 'react-navigation';
type Props = {
navigation: NavigationScreenProp<NavigationState>
};
标签:react-navigation,javascript,reactjs,flowtype,react-native 来源: https://codeday.me/bug/20190828/1747857.html