useParentMatches hook
useParentMatches
hook은 루트에서 현재 컨텍스트의 즉시 부모 매치까지의 모든 부모 RouteMatch
객체를 반환합니다. 현재 매치는 포함되지 않으며, 현재 매치는 useMatch
hook을 사용하여 얻을 수 있습니다.
[!IMPORTANT] 라우터에 대기 중인 매치가 있고 해당 매치가 대기 구성요소 폴백을 표시하는 경우,
router.state.matches
대신router.state.pendingMatches
가 사용됩니다.
useParentMatches options
useParentMatches
hook은 선택적인 options
객체를 허용합니다.
opts.select
option
- 선택 사항
(matches: RouteMatch[]) => TSelected
- 제공될 경우, 이 함수는 라우트 매치를 사용하여 호출되며, 반환 값은
useParentMatches
에서 반환됩니다. 이 값은 얕은 비교를 사용하여 hook이 부모 컴포넌트를 다시 렌더링할지 여부를 결정하는 데에도 사용됩니다.
opts.structuralSharing
option
- 타입:
boolean
- 선택 사항
select
에 의해 반환된 값에 대한 구조적 공유를 활성화할지 구성합니다.- 자세한 내용은 렌더링 최적화 가이드를 참조하세요.
useParentMatches returns
select
함수가 제공된 경우,select
함수의 반환 값.select
함수가 제공되지 않은 경우,RouteMatch
객체 배열.
Examples
import { useParentMatches } from "@tanstack/react-router";
function Component() {
const parentMatches = useParentMatches();
// ^ [RouteMatch, RouteMatch, ...]
}