Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
React 相当新,所以请原谅我。
我正在尝试使用来自 API 的数据构建实时仪表板。
当前的想法是使用 useEffect 以及 Fetch 和 API 上的间隔来提取数据并更新仪表板。这是最好的方法吗?我一直在阅读有关 EventSource 的内容,并认为这可能会更快?
useEffect是功能组件的一个反应钩子,用于替换/减少类组件内置方法:componentDidMount、、componentDidUpdate和componentWillUnmount仅一个钩子。
useEffect
componentDidMount
componentDidUpdate
componentWillUnmount
React 正在推动利用这个钩子,所以在我看来,如果你正在制作一个 react 应用程序,你应该使用 useEffect 来触发你的获取。