1
öğretici kaynak: A Duruma Bileşen - https://facebook.github.io/react/Eğiticiden tsx'i nasıl uygularım?
Bu benim kodudur: html olarak
interface Props {
}
interface State {
secondsElapsed: number,
}
class Timer extends React.Component<Props, State> {
private interval: number;
getInitialState() {
return { secondsElapsed: 0 };
}
tick() {
this.setState({ secondsElapsed: this.state.secondsElapsed + 1 });
}
componentDidMount() {
this.interval = setInterval(this.tick, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
}
ReactDOM.render(
<Timer />,
document.getElementById('example')
);
, bu timer.js:26 Uncaught TypeError: Cannot read property 'secondsElapsed' of null
döndürür. NULL neden saniyeElapsız?
Ne oldu?