I am pretty new to react native. I was doing fine with fetch()
until I fall into this problem:
I have a chat screen. (For clearness: I am using gifted-chat). So, when people enter in a conversation, I call a fetch and get all messages from my database(mysql db, php script). Then, I save to a state called data
.
At last, I show the messages. [It's pretty easy till now]. But the problem reveals itself when someone send me a message. The data is not updating. I know why this happens - it is not updating the state with the updated data because no further fetch()
is done.
I planned to call fetch()
with an interval like 1 second to get latest data but I think, this is not a good idea. Calling so much fetch()
is harmful surely.
Then, I think about real time data. My question is, how can get real time data from my mysql database using react native? I need to get real time data and update the state. But is it possible? Or how to do it?
I am not too older and very new to react native. Please forgive my problems and help me to get through this.
My snack: https://snack.expo.io/@nothingtosay/laughing-carrot
NOTE: I WILL NOT USE FIREBASE BECAUSE MY MAIN WEBSITE IS BASED ON MYSQL AND IT IS RUNNING
\
UPDATE: I have start using Socket.io to retrieve real time data. So thanks all. I don't need solution any more....