First of all thanks for ur time and ur reply! And second thing, then… there isnt any way to have the data reactive like i have it in the App.js render() {} component?
I mean, i will like to know if i can fire the data in the componentDidMount from the from the collection without using a setinterval / setimeout, to get in this case every second from the countdown.
Well anyways thanks for ur reply, have a good day!
You’re making things a lot harder than they need to be. You don’t need to keep sending data to all clients every second, only once. Even if you did, your clock wouldn’t tick every second due to latency.
Being off by half a second is more than acceptable in most situations because your users aren’t likely to open two windows side by side and notice the numbers being “slightly” off. You can use a smaller delay for setInterval to increase the accuracy of your clock though.
Thanks again manuel, i really apreciate the time u spend trying to help me a bit. I will check ur post slowly step by step, and figure it out all the things.
Just a little modification to handle client disconnections and errors.
From the React Doc it says this about componentDidMount():
If you want to integrate with other JavaScript frameworks, set timers using setTimeout or setInterval, or send AJAX requests, perform those operations in this method.
getServerTime() {
Meteor.call('getTargetDate', (err, targetDate) => {
if (!err) {
this.setState({
targetDate
})
} else {
setTimeout(() => {
getServerTime();
}, 1000); // Set as appropriate
});
}