S
SolidJS•17mo ago
Zanoryt

Now using createResource(), the content never loads.

const getReports = async () => {
return (await fetch('/api/reports')).json();
};

export default function Home() {
const [reports, { refetch }] = createResource(getReports);
...snip...

<Show when={!reports.loading} fallback={<tr><td>Loading...</td></tr>}>
<For each={reports()}>{item => (
<tr>
...snip...
</tr>
)}</For>
</Show>
...snip...
};
const getReports = async () => {
return (await fetch('/api/reports')).json();
};

export default function Home() {
const [reports, { refetch }] = createResource(getReports);
...snip...

<Show when={!reports.loading} fallback={<tr><td>Loading...</td></tr>}>
<For each={reports()}>{item => (
<tr>
...snip...
</tr>
)}</For>
</Show>
...snip...
};
All I ever see is Loading... in the rendering. I'm using SSR with Cloudflare Pages.
8 Replies
Zanoryt
ZanorytOP•17mo ago
Do I need to trigger it to load any other way? I am able to use createStore+createEffect, but wanted to use createResource.
Martnart
Martnart•17mo ago
This is a bit counter-intuitive. I'd been in the same situation when I started with solid. It would seem that the loading prop is meant for exactly the kind of code you showed but it's actually not doing anything in this case. You need to "access" the data, otherwise the resource will not do anything. For your case, I guess just rewriting the when condition would suffice when={reports() && !reports.loading}
Zanoryt
ZanorytOP•17mo ago
Yeah I did that too, and it didn't work. reports.loading would never be false
Martnart
Martnart•17mo ago
If you have a look here, this should work. Be mindful about ordering of the condition. reports() should come first. https://stackblitz.com/edit/solid-ssr-vite-2unf9c?file=src%2Froutes%2Findex.tsx In comparison, without call to the resource (your described behavior): https://stackblitz.com/edit/solid-ssr-vite-fzq4m5?file=src%2Froutes%2Findex.tsx
Zanoryt
ZanorytOP•17mo ago
I'll give that a shot 🙂
Silverdagger
Silverdagger•17mo ago
I have the exact same problem - any suggestions?
Martnart
Martnart•17mo ago
In what way does your problem differ that the proposed solution does not work? If you can show some code I might be able to help debug it
Silverdagger
Silverdagger•17mo ago
sure my problem is explained here - any help would be appreciated since i am new with solid in general https://discord.com/channels/722131463138705510/1145875082074407004
Want results from more Discord servers?
Add your server