0

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....

NothingtoSay
  • 162
  • 4
  • 14
  • see if that helps you further https://stackoverflow.com/a/22501154/5193536 – nbk Jun 27 '20 at 16:32
  • nbk Yeah, I already mentioned it. But is this a good idea to fetch again and again with an interval? Should I use it? – NothingtoSay Jun 27 '20 at 17:44
  • the mentioned push btechnology will be more fitting, but it is not well docomented and you will have a steep learning curve to implement it. sp for te first approach, you must test it with a lot of simulated clients, if the server can hold it. – nbk Jun 27 '20 at 17:53

0 Answers0