※ 공식문서를 읽고 정리한 글입니다.
import React, { useState } from 'react';
function Example() {
const [count, setCount] = useState(0);
/*
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
}
*/
<p>You clicked {count} times</p>
//<p>You clicked {this.state.count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
/*
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Click me
</button>
*/