移动页面后显示通过axios接收到的数据成功。但是当它被重新渲染时,这些字母就消失了。我不知道是哪一个问题。
const MyPage = ({ navigation, info }) => {
const [userInfo, setUserInfo] = useState();
const getData = async () => {
try {
axios
.get(
"http://everyweardev-env.eba-azpdvh2m.ap-northeast-2.elasticbeanstalk.com/api/v1/user"
)
.then((res) => res)
.then((data) => {
setUserInfo(data.data.data.result);
})
.catch((err) => console.log(err));
} catch (error) {}
};
useEffect(() => {
const unsubscribe = navigation.addListener("focus", () => {
getData();
});
return unsubscribe;
}, [navigation]);
return (
<View style={styles.container}>
{/*프로필*/}
<View style={styles.profileContainer}>
<Image source={require("../../images/profile.png")} />
<View style={styles.profileName}>
<TouchableHighlight>
<>
<Text
style={{
fontWeight: "bold",
marginBottom: hp("1%"),
fontSize: wp("7%"),
}}
>
{userInfo?._name} 님
</Text>
<Text
style={{
fontSize: wp("5%"),
}}
>
{userInfo?._mail}
</Text>
页面移动后