react component를 state에 넣어도 되는걸까? #598
airman5573
started this conversation in
Today I Learned
Replies: 1 comment
-
|
toss overlay-kit도 비슷한 방식이였떤것같아요! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
멘티가 만든 모달 컴포넌트를 보면서 뭔가 코드가 탐탁치 않았다.
const handleBtnClick = () => {
openModal();
};
음,, 저 jsx는 createElement를 호출하게 될텐데,,,좀 뭔가 불편했다.
그러나 하지 말라고할 이유를 찾지 못해서 좀 알아본다고 하고 마쳤다.
(조사후)
결론: 문제없음!
왜냐하면
react component가 렌더링하면 어차피 객체를 리턴함.
react state에 객체를 보관한다고 해서 문제될건 없음.
RealDOM에 insert 되고 나서 useEffect도 잘 실행됨.
렌더링 된거니까 update도 잘됨.
2016년에는 리액트 공식문서에 'state에는 UI관련된 작은 데이터만 넣으세요, 컴포넌트나 computed value는 넣지 마세요' 라고 명시 되어 있으나,
리액트 렌더링 흐름이나, 퍼포먼스 측정이나, 실제 fiber 쪽 코드나 문제 없음이 확인됨.
좋은거 배웠다!
Beta Was this translation helpful? Give feedback.
All reactions