Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swr vs axios with setInterval for large json data and high frequency in React

I am trying to build an application with large json data and sending get request every 7 seconds. So, both data size and frequency are high. Should i use swr or axios with react hooks and setinterval. I am using ag-grid and react-vis chart to display data.

There are 12 tables in every page with 30-100 rows. I am concerned about the performance issues.

I'm new to react. I need some suggestions deciding the libraries.

like image 984
Kumar Avatar asked Sep 21 '25 09:09

Kumar


1 Answers

The SWR library is more than just polling. One of its main functions is to provide a cache invalidation strategy. Besides, Request de-duplication, retry of exponential avoidance strategy, these functions are used out of the box, it is not recommended to implement it by yourself.

SWR first returns the data from cache (stale), then sends the fetch request (revalidate), and finally comes with the up-to-date data again.

It will give you a Real-time experience like WebSocket. Performance issues involve many aspects, using WebSocket may not be able to get good performance, you can try SWR

For more features, see features and performance

like image 68
slideshowp2 Avatar answered Sep 23 '25 00:09

slideshowp2