Refresh previous screen on goBack()

前端 未结 11 1802
天命终不由人
天命终不由人 2020-12-13 09:34

I am new to React Native. How can we refresh/reload previous screen when returning to it by calling goBack()?

Lets say we have 3 screens A, B, C:

<
11条回答
  •  隐瞒了意图╮
    2020-12-13 10:16

    Yes, constructor is called only for the first time and you can't call it twice.

    First: But you can separate the data getter/setter from the constructor and put it in a function, this way you can pass the function down to the next Scene and whenever you're going back you may simply recall the function.

    Better: You can make a go back function in your first scene which also updates the scene while going back and pass the go back function down. This way the second scene would not be aware of your update function which is reasonable.

    Best: You can use redux and dispatch a go-back action in your second scene. Then in your reducer you take care of going back & refreshing your scene.

提交回复
热议问题