So i am working on a IoT SaaS project in React. The user selects a sensor and a time range and receives data visualized in charts with a resolution about 5 minutes. My question is regarding best practices when handling fetching and saving of this data on the front-end. I have tried always fetching which works fine, but makes the system kind of slow. This is especially true while users are quickly switching back and forth between sensors. I have also tried saving the data, just as a json in the react state. This significantly increase performance, but has a lot of other problems. The browser starts complaining about ram uses and can sometimes get out of memory errors. There is also a lot of needed data handling as saving several non continuous data-ranges for the same sensor, locating and merging date-range overlaps etc...
So i am wondering what is the best practice here, should i always fetch or save on front-end? are there any frameworks i could use helping me with the data handling front-end or do i have to do this manually.