Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define props for react-navigation with Flow

I am working on a simple React Native App, and have decided to user react-navigation. I have also decided to go with Flow for static type checking. What I can't figure out, is how to define navigation related props with Flow.

e.g. I define my App.js to use StackNavigator like so:

import StackNavigator from 'react-navigation';
import Main from './app/containers/Main';

const App = StackNavigator({
  Main: { screen: Main },
});

export default App;

then I define my Main class, but I don't know how to reference react-navigation in my props:

// @flow

import React, { Component } from 'react';
import { View, Text } from 'react-native';

type Props = {
  navigate: ????
};

type State = {};

class Main extends Component<Props, State> {
   ...
}
like image 920
Finglish Avatar asked Dec 10 '22 07:12

Finglish


2 Answers

According to https://github.com/react-navigation/react-navigation/issues/3643

import { NavigationState, NavigationScreenProp } from 'react-navigation';

type Props = {
  navigation: NavigationScreenProp<NavigationState>
};
like image 188
user2473015 Avatar answered Dec 28 '22 06:12

user2473015


Import NavigationScreenProp from react-navigation:

// @flow
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import { NavigationScreenProp } from 'react-navigation';

type Props = {
  navigate: NavigationScreenProp<{}>
};

type State = {};

class Main extends Component<Props, State> {
   ...
}
like image 24
Hristo Eftimov Avatar answered Dec 28 '22 06:12

Hristo Eftimov