首页 > 解决方案 > React Native 使用导航类组件

问题描述

我正在使用一个类组件,我想从这里导航到另一个屏幕。但它说导航是未定义的。我查阅了文档,我意识到我需要使用userNavigationThis。但我不知道如何实际使用它。请有人帮忙

export default class ReduxScreen extends Component {
render() {
    return (
        <View>
           <Button block style={{ marginHorizontal: 30, marginTop: 50 }} onPress={() => {
         //I want to add the useNavigation here

            }}>
             <Text style={{ color: '#FFF' }}>Start</Text>
          </Button>
        </View>
    )
}}

标签: react-native

解决方案


<Link />像打击一样使用

import { Link } from 'react-router-dom';



export default class ReduxScreen extends Component {
render() {
    return (
        <View>
           <Button component={Link} to="some-where" block style={{ marginHorizontal: 30, marginTop: 50 }} 
            }}>
             <Text style={{ color: '#FFF' }}>Start</Text>
          </Button>
        </View>
    )
}}


推荐阅读