简体   繁体   中英

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. To get started I would recommend this egghead course .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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