Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 인접 형제 결합자
- id 선택자
- sup태그
- 아두이노
- 임베디드
- height속성
- 자식결합자
- Live Server
- 일반 형제 결합자
- RGBA
- iframe
- background-color 속성
- RGB
- width속성
- tag html
- html
- iframe 태그
- html tag i
- not 의사클래스
- html 태그
- br 태그
- css
- reveal in file explorer
- i 태그
- Checked 의사 클래스
- go live
- 전체 선택자
- padding 속성
- sub태그
- focus 의사클래스
Archives
- Today
- Total
so woon!
[React] 리렌더링 본문
학습일 : 2023. 03. 07
<script type="text/babel">
const root = document.getElementById("root");
function App() {
const [counter, setCounter] = React.useState(0);
const onClick = () => {
setCounter(counter + 1);
};
console.log("rendered");
console.log(counter);
return (
<div>
<h3>Total Clicks : {counter}</h3>
<button onClick={onClick}>Click Me!!</button>
</div>
);
}
ReactDOM.render(<App />, root);
</script>
modifier 함수를 사용하여 state 즉, 어플리케이션의 데이터를 바꿀 때
새로운 값을 가지고 컴포넌트 전체가 재생성된다.
이는 새로운 값을 가지고 리렌더링 된다는 의미이다.
좀 더 쉽게 예를 들자면,
counter가 원래 0이었는데 => 클릭을 하여 1로 세팅이 되면
리렌더링이 일어난다고 볼 수 있으며
개발자 도구를 확인해보면
리액트는 정말 똑똑한 아이라서
바뀌는 부분만 refresh 해준다는 것을 알 수 있다.
코드가 복잡해지고 길어진다는 것을 염두해 둔다면,
여러모로 효율성이 뛰어날 것이라 생각된다.
물론 아직까지는 체감이 잘 되진 않지만;;
'ReactJS > 개념정리' 카테고리의 다른 글
[React] Inputs, State (0) | 2023.03.11 |
---|---|
[React] State 바꾸기 (0) | 2023.03.07 |
[React] React.useState 사용하기 (0) | 2023.03.06 |
[React] render (0) | 2023.03.06 |
[React] JSX (0) | 2023.03.05 |
Comments