리액트 공식 문서 참고! !
그냥 적으면서 공부하는 느낌으로 사이트 내용을 쭉 적어보겠다
State can hold any kind of JavaScript value, including objects. But you shouldn't change objects
that you hold in the React state directly. Instead, when you want to update an object, you nedd to
create a new one (or make a copy of an exisitng one), and then set the state to use that copy.
Consider an object in state:
const [position, setPosition] = userState({ x : 0, y : 0});
Technically, it is possible to change the contents of the object itself. This is called a mutation:
position.x = 5;
However, although objects in React state are technically mutable, you should treat them as if they were
immutable - like numbers, booleans, and strings. Instead of mutating them, you should always replace them.
하핫 근데 글이 너무 길다
이 밑은 다음에 또 읽고 정리해보겠숩니다
'Web Programming' 카테고리의 다른 글
[React] vulnerability 문제 / error:03000086:digital envelope routines::initialization error (0) | 2024.03.03 |
---|---|
[JavaScript] 조건 (삼항) 연산자 (0) | 2024.03.03 |
[JavaScript] 스코프 / 스코프 체인 (0) | 2024.03.03 |
[JavaScript] Truthy vs Falsy (0) | 2024.03.03 |
[React] React와 DOM (0) | 2024.03.03 |