我正在学习react-native导航https://reactnavigation.org/docs/intro/.我在例子中看到了

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };
  render() {
    const { navigate } = this.props.navigation;
    return (
      <View>
        <Text>Hello, Chat App!</Text>
        <Button
          onPress={() => navigate('Chat')}
          title="Chat with Lucy"
        />
      </View>
    );
  }
}

我不明白这行代码到底是什么意思

推荐答案

语法与React Native无关

const { navigate } = this.props.navigation;

除了var和const之外,它与.

var navigate = this.props.navigation.navigate

不进行分解的示例应该如下所示

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };
  render() {
    return (
      <View>
        <Text>Hello, Chat App!</Text>
        <Button
          onPress={() => this.props.navigation.navigate('Chat')}
          title="Chat with Lucy"
        />
      </View>
    );
  }
}

React-native相关问答推荐

如何在使用嵌套的堆栈导航器在选项卡之间导航后弹出到堆栈顶部?

React Native Child Parent 通信

如何停止在 textInput React Native 中输入空格?

react-navigation中的React-native android后退按钮

React-native 组件的 elevation样式导致的阴影

如何更改 React Native(android)应用程序的远程推送通知图标

使用带有 react-native 的 WebView 设置用户代理

在 Windows 上进行本机调试

在react native 中出现Cannot read property 'pick算法rithm' of null错误

React Native STUCK 启动打包器

React Native Android 文本组件额外填充

创建新的 react-native 元素时出现Unexpected token import错误

Unexpected token on "export default const"

带有父 PanResponder 的 TouchableOpacity

KeyboardAvoidingView - 隐藏键盘时重置高度

如何在 React Native 中等待 Alert 对话框的响应?

居中图像 React Native 加载屏幕

React Native + Redux 基本认证

如何在 React 中将函数与钩子绑定?

在 React Native 中,两个等宽的按钮水平填充屏幕