<legend id='f2k9B'><style id='f2k9B'><dir id='f2k9B'><q id='f2k9B'></q></dir></style></legend>

    1. <small id='f2k9B'></small><noframes id='f2k9B'>

      <i id='f2k9B'><tr id='f2k9B'><dt id='f2k9B'><q id='f2k9B'><span id='f2k9B'><b id='f2k9B'><form id='f2k9B'><ins id='f2k9B'></ins><ul id='f2k9B'></ul><sub id='f2k9B'></sub></form><legend id='f2k9B'></legend><bdo id='f2k9B'><pre id='f2k9B'><center id='f2k9B'></center></pre></bdo></b><th id='f2k9B'></th></span></q></dt></tr></i><div id='f2k9B'><tfoot id='f2k9B'></tfoot><dl id='f2k9B'><fieldset id='f2k9B'></fieldset></dl></div>
      <tfoot id='f2k9B'></tfoot>

        <bdo id='f2k9B'></bdo><ul id='f2k9B'></ul>
      1. React Native - 如何更新 FlatList 的帖子(新的喜欢,...)

        React Native - how to update FlatList of posts (new likes, ...)(React Native - 如何更新 FlatList 的帖子(新的喜欢,...))

        • <tfoot id='M6BHf'></tfoot><legend id='M6BHf'><style id='M6BHf'><dir id='M6BHf'><q id='M6BHf'></q></dir></style></legend>

          1. <i id='M6BHf'><tr id='M6BHf'><dt id='M6BHf'><q id='M6BHf'><span id='M6BHf'><b id='M6BHf'><form id='M6BHf'><ins id='M6BHf'></ins><ul id='M6BHf'></ul><sub id='M6BHf'></sub></form><legend id='M6BHf'></legend><bdo id='M6BHf'><pre id='M6BHf'><center id='M6BHf'></center></pre></bdo></b><th id='M6BHf'></th></span></q></dt></tr></i><div id='M6BHf'><tfoot id='M6BHf'></tfoot><dl id='M6BHf'><fieldset id='M6BHf'></fieldset></dl></div>
              <bdo id='M6BHf'></bdo><ul id='M6BHf'></ul>

              <small id='M6BHf'></small><noframes id='M6BHf'>

                  <tbody id='M6BHf'></tbody>

                  本文介绍了React Native - 如何更新 FlatList 的帖子(新的喜欢,...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个帖子列表,它嵌套在一个平面列表中,该列表实现了拉动刷新,并且每个帖子(呈现在卡片中)都有上传它的用户的头像.此外,用户可以更改其头像,因此我需要使用新的用户头像更新帖子 FlatList.

                  I am developing a list of posts, which is nested in a flatlist that has a pull to refresh implemented, and each post (rendered in a Card) has the avatar of the user who uploaded it. Also, it is possible for a user to change its avatar, so I need to update the posts FlatList with the new user avatar.

                  我已经阅读了有关 ExtraData 道具的一些内容,但在我的情况下不起作用.

                  I have read something about the ExtraData prop but doesn't work in my case.

                  // Posts Screen
                  export default function Posts(props) {
                     const {
                        userData: {
                           username,
                           avatar
                        }
                     } = props;
                  
                     const [data, setData] = useState([]); // [{ avatar, username, photoUri, likes }, ...]
                  
                     let previousAvatar = useRef(avatar).current;
                  
                     // ... Fetch the data
                   
                     // This is the wrong(?) stuff I am doing to update the FlatList
                      useEffect(() => {
                       if (previousAvatar !== avatar) {
                         // For each post, change the avatar
                         setPosts(
                           posts.map((post) => ({
                             ...post,
                             avatar: avatar,
                           }))
                         );
                  
                         // Save the new avatar
                         previousAvatar = avatar;
                       }
                     }, [ownerData]);
                  
                  
                     return (<FlatList data={data} renderIt... />)
                     
                  }
                  

                  我在做什么

                  当我检测到用户更改了头像时,我会修改传递给 FlatList 的数据,从而更改头像 uri.我认为这很糟糕,因为列表中可能有 100K 帖子...

                  What I am doing

                  When I detect that the user has change its avatar, I modify the data which is passed to the FlatList, changing the avatar uri. I think this is bad, as there can be 100K posts in the list...

                  另外,当有新的喜欢、新的用户名时,我需要更新平面列表......所以我认为这是不可行的

                  Also, I need to update the flatlist when new likes, new username, ... So I think this is not viable

                  // Posts Screen
                  export default function Posts(props) {
                     const {
                        userData
                     } = props;
                  
                     ...
                      
                     return <FlatList data={data} extraData={userData} ... />
                  
                  }
                  

                  在文档中说通过将 extraData 传递给 FlatList,我们确保 FlatList 本身会在状态更改时重新渲染."但对我来说,这不起作用,因为 userData 是通过 props 接收的.

                  In the documentation says "By passing extraData to FlatList we make sure FlatList itself will re-render when the state changes.", but for me, this doesn't work, as userData is received via props.

                  有什么想法吗?谢谢.

                  推荐答案

                  flatList 将渲染数据而不是 extraData.尝试将 extraData 设置为布尔值,并在每次需要更新列表时反转布尔值.

                  flatList will render the data and not the extraData. try setting the extraData to a boolean and reverse the boolean value everytime you need to update the list.

                  这篇关于React Native - 如何更新 FlatList 的帖子(新的喜欢,...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Gradient Button to background-color blinks on hover(悬停时背景颜色的渐变按钮闪烁)
                  How to make hovering over active button not use hover effect?(如何使悬停在活动按钮上不使用悬停效果?)
                  html javascript show image hover(html javascript 显示图像悬停)
                  How to get css hover values on click?(如何在点击时获得 css 悬停值?)
                  Change background image on link hover(更改链接悬停时的背景图像)
                  Highlight multiple items on hover#39;s condition(突出显示悬停条件下的多个项目)

                  <small id='Q6OBm'></small><noframes id='Q6OBm'>

                    • <legend id='Q6OBm'><style id='Q6OBm'><dir id='Q6OBm'><q id='Q6OBm'></q></dir></style></legend>
                      • <bdo id='Q6OBm'></bdo><ul id='Q6OBm'></ul>
                        <tfoot id='Q6OBm'></tfoot>
                          <tbody id='Q6OBm'></tbody>

                            <i id='Q6OBm'><tr id='Q6OBm'><dt id='Q6OBm'><q id='Q6OBm'><span id='Q6OBm'><b id='Q6OBm'><form id='Q6OBm'><ins id='Q6OBm'></ins><ul id='Q6OBm'></ul><sub id='Q6OBm'></sub></form><legend id='Q6OBm'></legend><bdo id='Q6OBm'><pre id='Q6OBm'><center id='Q6OBm'></center></pre></bdo></b><th id='Q6OBm'></th></span></q></dt></tr></i><div id='Q6OBm'><tfoot id='Q6OBm'></tfoot><dl id='Q6OBm'><fieldset id='Q6OBm'></fieldset></dl></div>