import{ React, useContext} from 'react';
import { Button, View, Text } from 'react-native';
import { NavigationContainer, useNavigation ,useRoute } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { LoginContexts } from '../Contexts/LoginContexts';
function Screen2() {
const {getEmail} = useContext(LoginContexts);
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<LoginContexts.Consumer >
<Text>{getEmail}</Text>
</LoginContexts.Consumer>
</View>
);
}
export default Screen2;
這是我的消費者部分,我想在文本視圖中顯示 getEmail 中存在的文本。請幫助解決這個問題。
uj5u.com熱心網友回復:
問題是該LoginContexts.Consumer組件需要一個渲染功能。
背景關系消費者
<MyContext.Consumer> {value => /* render something based on the context value */} </MyContext.Consumer>
該useContext掛鉤是消費者,去掉LoginContexts.Consumer部分。
function Screen2() {
const {getEmail} = useContext(LoginContexts);
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>{getEmail}</Text>
</View>
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/421076.html
標籤:
