T
TanStack12mo ago
future-harlequin

Query tree data structure with parent-children loading

Hello everyone, I'm working on an app with a page system similar to Notion, where I need to load data asynchronously. The goal is to initially load only the parent pages, and then, when a parent node is expanded, load its child pages via an async query. I'm considering using useInfiniteQuery for this, but the challenge is that the tree structure isn't loaded in a linear order. Users can expand any parent at any time, meaning pages can be opened in a random sequence. Is there a way to pass a parentId to the getNextPageParam function to load children dynamically? If not, what query method would you recommend to manage and cache data for a tree structure like this, where pages and their children are queried on demand? I'd appreciate any advice or recommendations. Thanks in advance!
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?