-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
query client를 clientRef.current에 저장하는 이유가 무엇인가요~?
21.12.03 10:28 작성 조회수 222
0
new QueryClient()
위 객체를 useState의 setState()로 state에 저장할 수도 있는데 useRef를 써서 ref.current에 저장하는 이유가 따로 있는지 궁금합니다! useRef는 html tag의 reference를 참조할 때 쓰는 걸로 알고 있어서요 :)
답변을 작성해보세요.
1
정재남
지식공유자2021.12.03
useRef는 html tag의 reference를 참조할 때에만 쓰는 것이 아닙니다.
current에 언제나 최신정보가 반영되길 기대하면서,
동시에 current의 값이 변경되더라도 재랜더링을 일으키지 않길 원하는 모든 경우에
어떤 데이터든 넣을 수 있습니다.
https://reactjs.org/docs/hooks-reference.html#useref
Keep in mind that useRef
doesn’t notify you when its content changes. Mutating the .current
property doesn’t cause a re-render. If you want to run some code when React attaches or detaches a ref to a DOM node, you may want to use a callback ref instead.
답변 1