简体   繁体   English

如何让 React 组件从后端接收更新?

[英]How to make a react component receive updates from the back-end?

I'm working on an application that multiple users can collaborate on at the same time.我正在开发一个多个用户可以同时协作的应用程序。 If a user make changes to the database, how do I update the component for other users?如果用户对数据库进行了更改,我如何为其他用户更新组件? Do I need to make a function that runs every minute for example and check to see if the database has changed and then apply those changes, or is there a better way?例如,我是否需要创建一个每分钟运行一次的函数并检查数据库是否已更改,然后应用这些更改,还是有更好的方法?

You may implementWebSockets to get live updates from the backend.您可以实现WebSockets以从后端获取实时更新。 LongPolling is also possible but less efficient. LongPolling 也是可能的,但效率较低。

The Websocket implementation depends on what technology you are using on the backend, if you are using NodeJS, check out this link - WebSockets/ws Otherwise just google WebSockets + technology term Websocket 实现取决于您在后端使用的技术,如果您使用的是 NodeJS,请查看此链接 - WebSockets/ws否则只是谷歌 WebSockets + 技术术语

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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