npx create-react-app typescript-react-demo --typescript
App.tsx
import React, { Component } from "react";
import {createGlobalStyle} from "styled-components";
// 컴포넌트에게 state가 있다는 걸 알려주는 것
interface IState {
counter : number;
}
// 컴포넌트에게 state 부여
class App extends Component<{}, IState> {
state = {
counter : 0
};
render() {
const {counter} = this.state;
return (
<div>
{counter} <button onClick={this.add}>Add</button>
</div>
);
};
add = () => {
this.setState(prev => {
return {
counter : prev.counter + 1
}
})
}
}
export default App;