# Demo

作者:Odboy (opens new window)

本站地址:https://blog.odboy.cn (opens new window)

# 文件后缀

*.jsx
1

# Demo

import React, {Component} from 'react';

class Timer extends Component {
    constructor(props) {
        super(props);
        this.state = {seconds: 0};
    }

    componentDidMount() {
        this.interval = setInterval(() => {
            this.setState(state => ({
                seconds: state.seconds + 1,
            }));
        }, 1000);
    }

    componentWillUnmount() {
        clearInterval(this.interval);
    }

    render() {
        return <h1>Seconds: {this.state.seconds}</h1>;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
最近更新: 2025-04-09
Demo

2017 - 武林秘籍   |