Я пытаюсь использовать easytimer.js в своем приложении React (используется приложение create-response-app). Но я получил следующую ошибку:
Failed to compile
./src/easytimer.js
Line 10: 'define' is not defined no-undef
Line 11: 'define' is not defined no-undef
Вот мой код.
Я тестировал коды, и он работает без ошибок.
Любая помощь будет высоко оценен!
@MaddEye Да, ваше решение работает, спасибо. Теперь у меня другая ошибка (TypeError: не удается прочитать свойство «таймер» неопределенного значения в строке 19). Не знаете, как сохранить ссылку на таймер ... может кто-нибудь помочь? gist.github.com/noblesilence/f27baef6beda6edf8a6569cbb925b8f d





Вот ваше решение
Код Timer.js:
import React, { Component } from "react";
import EasyTimer from "easytimer";
class App extends Component {
constructor() {
super();
this.state = {
timer: new EasyTimer(),
timeValues: ""
};
this.tick = this.tick.bind(this);
}
componentDidMount() {
let { timer } = this.state;
timer.start();
timer.addEventListener("secondsUpdated", this.tick);
}
tick(e) {
let { timer } = this.state;
const timeValues = timer.getTimeValues().toString();
this.setState({ timeValues: timeValues });
}
render() {
return <div className = "App">{this.state.timeValues}</div>;
}
}
export default App;
кто-то уже, но это в пакет npm, который легче использовать maby: npmjs.com/package/easytimer