简体   繁体   English

传递参数时,undefined 不是本机反应中的对象(评估“_this.props.navigation”)

[英]undefined is not an object (evaluating '_this.props.navigation') in react native when passing parameter

im passing parameter from screen A to screen B我将参数从屏幕 A 传递到屏幕 B

Screen A :屏幕 A:

<Button
          title="Go Next"
          onPress={() =>
            navigate('liveScreen', {
              linkItem: this.state.link,
            })
          }
        />

Screen B :屏幕 B:

import React, { useEffect } from 'react';
import JitsiMeet, { JitsiMeetView } from 'react-native-jitsi-meet';

function linkScreen() {

  useEffect(() => {
    setTimeout(() => {
      const url = `https://meet.jit.si/${this.props.navigation.state.params.linkItem}`;
      const userInfo = {
        displayName: 'User',
        email: 'user@example.com',
        avatar: 'https:/gravatar.com/avatar/abc123',
      };
      JitsiMeet.call(url, userInfo);
    }, 1000);
  }, [])

  useEffect(() => {
    return () => {
      JitsiMeet.endCall();
    };
  });

  function onConferenceTerminated(nativeEvent) {
    console.log(nativeEvent)
  }

  function onConferenceJoined(nativeEvent) {
    console.log(nativeEvent)
  }

  function onConferenceWillJoin(nativeEvent) {
    console.log(nativeEvent)
  }
  return (
    <JitsiMeetView
      onConferenceTerminated={e => onConferenceTerminated(e)}
      onConferenceJoined={e => onConferenceJoined(e)}
      onConferenceWillJoin={e => onConferenceWillJoin(e)}
      style={{
        flex: 1,
        height: '100%',
        width: '100%',
      }}
    />
  )
}
export default linkScreen;

but theres an error on screen B that say 'undefined is not an object (evaluating '_this.props.navigation')'但是屏幕 B 上有一个错误,说“未定义不是对象(正在评估 '_this.props.navigation')”

im using react-native-jitst-meet to create simple confrence app for class project.我正在使用 react-native-jitst-meet 为课堂项目创建简单的会议应用程序。 I really hope you guys can give the solution.真心希望大家能给出解决方案。 Thankyou before之前谢谢你

You are using a functional component.您正在使用功能组件。 So you cant access it as this.props.navigation所以你不能作为 this.props.navigation 访问它

First you have to add the props like below首先,您必须添加如下道具

function linkScreen({navigation}) {

Then you can access it like below然后你可以像下面一样访问它

const url = `https://meet.jit.si/${navigation.state.params.linkItem}`;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 undefined 不是一个对象(评估&#39;this.props.navigation&#39;)-React Native - undefined is not an object (evaluating 'this.props.navigation') - React Native TypeError:undefined 不是 React Native 中的对象(评估“_this.props.navigation”) - TypeError: undefined is not an object (evaluating '_this.props.navigation') in React Native undefined不是评估_this.props.navigation React Native的对象 - undefined is not an object evaluating _this.props.navigation React Native 如何解决React Native中的导航问题(TypeError:undefined不是一个对象(评估&#39;_this.props.navigation)) - How to fix navigation problem in React Native (TypeError: undefined is not an object (evaluating '_this.props.navigation) React Native 中的堆栈导航器。 错误“undefined is not an object (evaluating this.props.navigation)” - Stack Navigator in React Native. Error "undefined is not an object (evaluating this.props.navigation)" 未定义不是对象(评估“ this.props.navigation”) - undefined is not an object (evaluating 'this.props.navigation') undefined不是对象(评估this.props.navigation) - undefined is not an object (Evaluating this.props.navigation) 未定义不是对象(评估“ this.props.navigation”) - undefined is not an object (evaluating “this.props.navigation”) undefined 不是带有 fetch 的 object(评估“this.props.navigation”) - undefined is not an object (evaluating 'this.props.navigation') with fetch 未定义不是对象(评估“ this.props.navigation”) - undefined is not an object (evaluating 'this.props.navigation")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM