简体   繁体   English

React Native:检查组件是否返回

[英]React Native: Check if component is returned to

I'm wanting to refresh a component once it has been returned to from a child component. 我想从子组件返回到某个组件后刷新它。 I currently have a dogs page that lists dogs that a user can click on. 我目前有一个“狗”页面,其中列出了用户可以单击的狗。 The user can delete a dog on the dog page and I would like this change to be reflected in the dogs page when they press 'Back' to return to the dogs page. 用户可以在狗页面上删除狗,当他们按下“返回”返回到狗页面时,我希望此更改能够反映在狗页面中。 Does anyone know of a callback or any other way I can detect that a user has returned to the dogs page from a dog page? 有谁知道回调或我可以检测到用户已从狗页面返回到狗页面的任何其他方式?

One way to solve this problem is to add a callback from your top level component into the rendered navigator. 解决此问题的一种方法是将顶级组件中的回调添加到呈现的导航器中。 This would be a hacky but quick solution. 这将是一个骇人但快速的解决方案。 To address this issue on a solid base I would encourage you to try redux , it has a single source of truth, so removing a dog (via an action) would cause all other data dependent components to rerender. 为了稳固地解决此问题,我建议您尝试redux ,它有一个单一的事实来源,因此(通过操作)删除一条狗将导致所有其他依赖数据的组件重新呈现。 To get started I would recommend this egghead course . 首先,我会推荐这个蛋头课程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM