#loader for nested route components

2 messages · Page 1 of 1 (latest)

balmy trail
#

If I have a route which has several child components and each component requires some data loading, how can I add loader functions to child components? do I load data the traditional way with useQuery or should I load all data in the route and pass it to each child? or is there a better way?

 /route-a:
    <ChildComponent/> // requires data loading
    <ChildComponent2/> // requires data loading

only the route has the loader function
open robin
#

If you are already using TanStack Query, then you can just load the data at /route-a, and call useSuspenseQuery on the child routes for it.