I'm coding in React Native and need to get a value from Google Firebase in real time. I am able to get the value (1), but when the value in the database changes, the textbox in my application does not change accordingly (2). In other words, real-time synchronization with the database is not implemented. I can't figure out why. Will you help me with this problem? Thank you so much! The code I wrote is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
I need to get a value from Google Firebase in real time, and when it changes in the database, I need it to change in the textbox as well.
P粉6708387352023-09-14 14:28:02
This is because data is loaded from Firebase (and pretty much any modern cloud API) asynchronously, and is not yet available when your <Text style={styles.text}>{Data}</Text>
is executed.
You'll want to:
The common way to do this is by using the useState
and useEffect
hooks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
This is a quite complex topic, so I recommend reading up on both of the hooks used here and also see: