1

I am using RN 0.54 with react-navigation having 3 tabs - tanks, alerts, and settings. I want to navigate and reload the alerts tab whenever I receive a notification for alerts.

I am able to navigate to the alerts screen when I am in either tanks or settings tab but when I get a notification while I'm in the alerts tab, nothing happens.

Now I want to reload the alerts screen while I'm on the alerts screen when I receive a notification.

Any lead would be greatly appreciated.

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
HungrySoul
  • 1,151
  • 2
  • 17
  • 31

1 Answers1

0

Going by the React philosophy, reloading screens shouldn't be done.

In my opinion, what you can do is, you place all your alerts in a state and use setState({}) whenever a notification arises. This way, you can refresh your alert screen without reloading the screen.

EDIT

Adding to the answer, it can still be achieved via states.

A primary state can be maintained. For example isReloaded: false:

Whenever a notification comes, setState({isReloaded: true}) and in your render() method you can call a function which fetches you new data and updates the state accordingly (you'll have to do a this.state.isReloaded = false inside this function, to enable it to be called again).

Aseem Upadhyay
  • 4,279
  • 3
  • 16
  • 36
  • Sorry, i should have mentioned this in the question. I have a flatlist in alert screen. What i meant by reload is calling a fetch and updating my state with new data. i want to perform this action when i receive a new alert notification. – HungrySoul Mar 14 '18 at 12:18
  • let me give it a try. – HungrySoul Mar 14 '18 at 12:35