본문 바로가기

React

[React] useState, props

 

# 리액트 튜토리얼

## 0. 참고하면 좋을 사이트


## 1. state

let account = 0x000ads0affads;

<h1>{account}</h1>

account=1faadsfadsfadsf

- 데이터가 저장되는 곳, 변할때 마다 자동 렌더링

```js
const [counter, setCounter] = useState(0); // number
const [loading, setLoading] = useState(true); // boolean
const [weather, setWeather] = useState([]); // list

const onClick = () => {
setCounter((current) => current + 1);
};
```

## 2. props

- 부모 컴포넌트로 부터 자식 컴포넌트에 state를 보낼 수 있게 하는 방법

```js
<Props weather={weather} count={counter} />
```