티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as React from 'react';
//https://react-etc.vlpt.us/06.typescript-basic.html
interface CounterProps {
    startNumber: number;
}
 
interface CounterState {
    number: number;
}
 
class Counter extends React.Component<CounterProps, CounterState> {
    public state = {
        number: 0,
    }
 
    constructor(props: CounterProps) {
        super(props);
        this.state.number = props.startNumber;
    }
 
    public handleClick = () => {
        this.setState({
            number: this.state.number + 1,
        });
    }
    public render() {
        return (
            <div>
                <h1>{this.state.number}</h1>
                <h1>{this.props.startNumber}</h1>
                <button onClick={this.handleClick}>Click Me</button>
            </div>
        )
    }
}
 
export default Counter;
cs

 

App.tsx

 

1
2
3
4
5
6
7
8
9
10
11
import React from 'react';
import './App.css';
import Counter from './oop/Counter';
class App extends React.Component {
    public render() {
        return <Counter startNumber={0/>;
    }
}
 
export default App;
 
cs
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함