컴포넌트의 속성을 의미하며, 주로 상위 컴포넌트에서 하위 컴포넌트에 값을 전달할 때 사용한다.
props를 전달하는 또 다른 방법으로 children
을 이용하여 해당 value에 접근이 가능하다.
const App = () => (
<Category>
<li>First item.</li>
<li>Second item.</li>
<li>Another item.</li>
</Category>
);
const Category = ({ children }) => {
return <ul>{children}</ul>;
};
값을 저장하거나 변경할 수 있는 객체로 보통 이벤트와 함께 사용된다.
state 사용 시 주의점
예를 들어 state[1]=3;
, state.push(1);
이런식으로 강제 변경하면 리렌더링이 일어나지 않는다.
따라서 setState
함수를 이용해 변경해야 한다.
Bare Minimum까진 문제가 없었지만 Advanced 과제인 트윗 필터링과 삭제 구현이 좀 힘들었다.
const handleSelectClick = (event) => {
setNewData(dummyTweets.filter((el) => el.username === event.target.value));
};
<div className="tweet__selectUser">
<select onChange={handleSelectClick}>
<option value="">-- click to filter tweets by username --</option>{options}</select>
const handleDelete = (event) => {
setNewData(
newData.filter(
(element) => element.id !== Number(event.target.attributes.id.value)
)
);
};
삭제 구현 부분에서 페이지 이동이나 새로고침을 할 때마다 다시 기존 데이터로 돌아와버려서 localStorage를 이용해볼려 그랬는데 로컬에서는 제대로 동작하지만 테스트 통과가 안됐다...뭐가 문젠지 모르겠다...
참고자료
https://developer-talk.tistory.com/226
https://goddaehee.tistory.com/301
https://goddaehee.tistory.com/300?category=395445
https://www.daleseo.com/react-hooks-use-web-storage/