Fetching nested data on SSR'd page #2137
-
|
Hi, I'm evaluating different frameworks for my startup and Blitz is certainly looking very solid, kudos to the authors and community! As for my specific question, I want like to SSR a page with a complex hierarchy of components (some pseudo code below) <Page>
<CompA> // uses DataA, needs it for SSR
<CompB> // uses DataB, can be client-side loaded
<CompC/> // uses DataA and DataC, needs it for SSR
</>
</>
</>and I'd like to be able to smartly determine which data should be fetched from In the example above it would be Is there an established pattern, library or built-in to accomplish this? What I'm trying to avoid is:
Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
If CompA and CompC are querying data with export default function Page({ initialDataA, initialDataB, initialDataC }) {
return (
<CompA initialData={initialDataA}>
<CompB>
<CompC initialData={initialDataC} />
</CompB>
</CompA>
)
}
export async function getServerSideProps({ req, res }) {
const initialDataA = await (...)
const initialDataC = await (...)
return { props: { initialDataA, initialDataC } }
}and a CompA like: interface Props {
initialData: SomeDataObject
}
function CompA({ initialData }: Props) {
const { data } = useQuery(getDataA, inputs, { initialData: initialDataA })
return (...) // do something with query data
}if your components are well-defined and you're using TypeScript to define your Props, then this issue basically becomes a compilation error; the code simply won't compile until you've provided a valid initialData prop to CompA, which you can only do by writing the gSSP. However, it sounds like you're thinking of it as if CompA is dictating to gSSP about whether or not the page should be server rendered, but that isn't the component's job. Actually it is gSSP that is responsible for making that happen. So you could delete the |
Beta Was this translation helpful? Give feedback.
-
|
I think currently we don't have a good pattern for this, but we absolutely want to support this. Probably we'll wait for server components to land as there's likely significant overlap with that. |
Beta Was this translation helpful? Give feedback.
I think currently we don't have a good pattern for this, but we absolutely want to support this. Probably we'll wait for server components to land as there's likely significant overlap with that.