【问题标题】:react-native: Letters disappear after re-rendering On the current page in react-nativereact-native:重新渲染后字母消失在react-native的当前页面上
【发布时间】:2021-07-26 23:32:11
【问题描述】:

移动页面后显示通过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>

页面移动后

重新渲染后

【问题讨论】:

    标签: react-native letter viewdiddisappear


    【解决方案1】:

    我认为您的情况不是re-rendering,而是refreshing

    有什么区别?
    re-rendering 发生在更新状态之后。
    refreshing 发生在编辑器中编辑文件之后。

    如果您的情况确实是refreshing,请不要担心它只是在调试版本的development 期间发生,而在发布版本中没有发生。

    【讨论】:

    • 意为提神醒脑。如果发布时没有发生,我会这样做。谢谢。我以为是代码有问题。
    猜你喜欢
    • 2018-09-02
    • 2019-09-26
    • 2018-12-27
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 2018-12-26
    相关资源
    最近更新 更多