react web game : 로또추첨기 - 클래스 컴포넌트

This commit is contained in:
haerong22
2021-03-07 19:08:17 +09:00
parent 70dd095285
commit b0f96c966b

View File

@@ -27,7 +27,7 @@ class Lotto extends Component {
timeouts = [];
componentDidMount() {
runTimeouts = () => {
const { winNumbers } = this.state;
for (let i = 0; i < this.state.winNumbers.length - 1; i++) {
this.timeouts[i] = setTimeout(() => {
@@ -44,6 +44,10 @@ class Lotto extends Component {
redo: true,
});
}, 7000);
};
componentDidMount() {
this.runTimeouts();
}
componentWillUnmount() {
@@ -52,6 +56,22 @@ class Lotto extends Component {
});
}
componentDidUpdate(prevProps, prevState) {
if (this.state.winBalls.length === 0) {
this.runTimeouts();
}
}
onClickRedo = () => {
this.setState({
winNumbers: getWinNumbers(),
winBalls: [],
bonus: null,
redo: false,
});
this.timeouts = [];
};
render() {
const { winBalls, bonus, redo } = this.state;
return (