Currently, I am working on a timer application in React Native and aiming to display the elapsed milliseconds using state management. The guide I am referring to is slightly outdated as it uses plain JavaScript instead of ES6, so I took it upon myself to convert the code into ES6 syntax. However, I encountered a small issue where pressing the start button triggers an error mentioning that 'undefined' is not a function. Despite my attempts to rectify this by adjusting several elements, nothing seems to work.
...
class App extends Component {
constructor(props) {
super(props);
// Initialize your state here
this.state = {
timeElapsed: null
}
}
// getInitialState() {
// return {
// timeElapsed: null
// }
// }
render() {
return (
<View style={styles.container}>
<View style={[styles.header, this.border('yellow')]}>
<View style={[styles.timerWrapper, this.border('red')]}>
<Text>
{this.state.timeElapsed}
</Text>
</View>
...
</View>
);
}
...
handleStartPress() {
let startTime = new Date();
// Update our state with some new value
setInterval(() => {
this.setState({
timeElapsed: new Date() - startTime
});
}, 30);
}
...
}
I am seeking advice on resolving this matter using JavaScript and ES6. My intuition suggests that the issue may be related to the binding process, but my efforts have not yielded any positive outcomes yet. Any assistance offered would be greatly appreciated! Thank you in advance.