[英]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.