-
Apologies if this has been answered before, I had trouble finding an answer. I'm trying to figure out how to structure some of my components. My basic task is this: I'd like to make a page that can show, for a given dataset, the information about the dataset, the list of its tasks, and the list of its versions. Essentially, I'm thinking of something like this: let dataset_information = create_resource(|| (), |_| async move { retrieve_dataset_info().await })
view! {
<DatasetInfo dataset_information>
<DatasetTaskList dataset_information>
<DatasetVersionList dataset_information>
} where But I'm having trouble deciding what is the best way of doing this. I've been testing out 3 options:
That sort of indicates to me that this approach is wrong for web development, which again I'm not used to. But I couldn't tell if that comment was meant for SSR pages, or for resources in general.
let dataset_information: Resource<(), Dataset> = create_resource(|| (), |_| async move { retrieve_dataset_info().await })
view! {
<div>
{
move || {
let dataset=dataset_information.get().unwrap();
view ! {
<DatasetInfo dataset>
<DatasetTaskList dataset>
<DatasetVersionList dataset>
}
}
}
</div>
} (I haven't really worked this one out yet so I'm not sure that that code is correct) Basically, I'm just looking for advice. Should I try to fetch all my data at once? Should I create resources that fire when other resources update? Or should reacting to my resources create new resources? (As a side question, is it better for components to have parameters of a Thanks Footnotes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Does the If
After 4 full round trips to the server and back, you're finally ready to render the page. If it's at all possible, you should try to join the three separate GET requests for data into a single request that can return all the data that is needed on a particular page. This will have a much larger performance impact than anything else.
This is the best approach. The 3 GET requests will run concurrently. If you can structure your API so that they are 1 GET request, that's much better, but at least this way avoids the waterfall. If I am misunderstanding and the 3 requests can be run independently, without The ideal situation would be one in which any of the three fields could be fetched separately, with only (for example) a dataset ID, rather than the full dataset, which would allow you to create three resources that can reload independently to refresh separate pieces of the data, but can all run concurrently. Part of the reason that resource waterfalls are a pain to implement is that resource waterfalls are bad. |
Beta Was this translation helpful? Give feedback.
You're absolutely right about Suspense -- with the waterfall, you could have nested spinners
Running the three requests concurrently lets compress that into a single spinner for loading all the data, which will be loaded faster, so probably a better UX but of course it's up to you!
Re: deriving
Signal
fromResource
-- yes, should be fine, just remember that it's a lossy conversion in the sense that you lose access to things likeResource::refetch()
if what you have is aSignal
not aResource
. In general I'd only convert them toSignal
if you're either actu…