I use Meteor/React.
Is there anyway to compare current data with the previous one to decide whether it needs to render the view or to manipulate the data which has high costs and is inefficient?
// use react-meteor-data to bind the Meteor data to React components
createContainer((props) => {
Meteor.subscribe('some_collectoin');
// fetch the new data
const data = SomeCollection.findOne({...});
// get the previous data for comparison
const previousData = ... // how to get it?
const previousResults = ... // how to get it?
// only update the results if required
let result;
if (needsUpdate(data, previousData)) {
// Calling calculateResult() is heavy work. Should avoid calling this as possible.
result = calculateResult(data);
} else {
// if data is not changed, use the same results and skip rendering the page
result = previousResults;
// how to skip page rendering?
}
return {
data: data,
results: results
};
}, ChartComponent)