简体   繁体   中英

How to change user page content without refresh

I have a react js app with a video player window, using Firebase database. I have an admin panel that can change the url of the video shown.

I want when the admin change the video displayed, the video shown of users in the other side, changed without refresh rhe page.

How can I do that?

I think you should use WebSockets ( https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications ). The client will listen for changes and change state inside the component.

I found an easy way using Firebase.Get realtime updates with Cloud Firestore.

onSnapshot() function

You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM