undefined 在传递参数时不是 object(评估'_this.props.navigation')
undefined is not an object (evaluating '_this.props.navigation') in react native when passing parameter
我正在将参数从屏幕 A 传递到屏幕 B
屏幕 A:
<Button
title="Go Next"
onPress={() =>
navigate('liveScreen', {
linkItem: this.state.link,
})
}
/>
屏幕 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;
但屏幕 B 上出现错误,提示“undefined is not an object (evaluating '_this.props.navigation')'
我正在使用 react-native-jitst-meet 为 class 项目创建简单的会议应用程序。真心希望大家能给出解决办法。先谢谢你
您正在使用功能组件。
所以你不能访问它作为 this.props.navigation
首先你必须添加如下道具
function linkScreen({navigation}) {
然后就可以像下面这样访问了
const url = `https://meet.jit.si/${navigation.state.params.linkItem}`;
我正在将参数从屏幕 A 传递到屏幕 B
屏幕 A:
<Button
title="Go Next"
onPress={() =>
navigate('liveScreen', {
linkItem: this.state.link,
})
}
/>
屏幕 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;
但屏幕 B 上出现错误,提示“undefined is not an object (evaluating '_this.props.navigation')'
我正在使用 react-native-jitst-meet 为 class 项目创建简单的会议应用程序。真心希望大家能给出解决办法。先谢谢你
您正在使用功能组件。 所以你不能访问它作为 this.props.navigation
首先你必须添加如下道具
function linkScreen({navigation}) {
然后就可以像下面这样访问了
const url = `https://meet.jit.si/${navigation.state.params.linkItem}`;