本文介绍了在堆栈弹出时反应本机路由通量重新渲染组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何重新运行 React 组件生命周期方法以确定在使用 反应本机路由器通量?

场景:场景A -> B -> A假设 A 是初始场景,我们通过 push 即 Actions.SceneB 从 A 导航到 B.从 B 到 A,伴随着 Pop.当堆栈弹出以显示场景 A 时,不会为场景 A 调用任何 React 组件方法.如何确定是否需要重新渲染?我搜索了 github repo 上列出的问题,许多似乎没有解决方案的问题.这个问题是如何解决的?

How do you re-run React Component Lifecycle methods to determine if a re-render is necessary when transitioning back to previous screens from stack using React Native Router Flux?

Scenario: Scene A -> B -> ALets say, A is the initial scene and we navigate from A to B with a push i.e Actions.SceneB. From B to A with a Pop. When the stack is popped to show Scene-A, none of the React Component methods are called for Scene-A. How do I determine if a re-render is necessary? I searched the Issues listed on the github repo and many seems to have this problem without a solution. How is this problem addressed?

我有一个用 setTimeout 调用 Actions.refresh() 的丑陋工作.

I have the ugly work around of calling Actions.refresh() with a setTimeout.


解决这个问题!这种解决方法似乎很棘手.必须有更好的方法来挂钩组件生命周期以确定是否需要重新渲染.也许回调到组件?


Work Around that works!This workaround seems to be hacky. There must be a better way to hook into component lifecycle to determine if a re-render is required. Perhaps a callback into the Component?

<TouchableHighlight underlayColor='#efefef' onPress={() => { Actions.pop(); setTimeout(()=> Actions.refresh(), 500)}} style={styles.cancel}>

不起作用的选项

Actions.pop({type: 'reset'})

          OR

Actions.refresh({"key" : "sceneA"})

推荐答案

解决这个问题!这种解决方法似乎很棘手.必须有更好的方法来挂钩组件生命周期以确定是否需要重新渲染.

Work Around that works! This workaround seems to be hacky. There must be a better way to hook into component lifecycle to determine if a re-render is required.

<TouchableHighlight underlayColor='#efefef' onPress={() => { Actions.pop(); setTimeout(()=> Actions.refresh(), 500)}} style={styles.cancel}>

这将调用 shouldComponentUpdate() 方法,该方法提供一个选项来确定是否需要重新渲染.

This will call shouldComponentUpdate() method which gives an option to determine, if a re-render is required.

这篇关于在堆栈弹出时反应本机路由通量重新渲染组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 08:27