запустить setInterval в componentDidMount и обновлять состояние каждую секунду.
state = {
time: 0,
};
componentDidMount() {
this.timer = setInterval(() => {
this.setState(prev => {
return {
time: prev.time + 1,
};
});
}, 1000);
}
componentWillUnmount() {
clearInterval(this.timer);
}
и извлекать секунды, минуты, часы
const { time } = this.state;
const hours = Math.floor(time / 3600);
const minutes = Math.floor((time - hours * 3600) / 60);
const seconds = time - minutes * 60 - hours * 3600;
Вот выставка demo