React Navigation 'navigation' is missing in props validation
React.PropTypes
has moved into the prop-types
package since React v15.5 (see Typechecking with PropTypes).
It should be used instead of importing from react-native
(the package can be added into the project via npm install --save prop-types
or yarn add prop-types
).
And the example code complying with "Component should be written as a pure function" rule as follows:
// In addition to other imports:
import PropTypes from 'prop-types';
const LoginScreen = ({ navigation }) => (
<View>
<Button
title="Login"
onPress={() => navigation.navigate('MainScreen')}
/>
</View>
);
LoginScreen.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
};
Solution today (since object Proptype isn't accepted by default anymore):
export default class LoginScreen extends Component {
static propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
}
}