Sun「無用」
Sun「無用」
Explore posts from servers
SSolidJS
Created by Sun「無用」 on 3/17/2023 in #support
createResource returning undefined when data is fetched
I'm just learning solid and did something like a hook? maybe? dunno. Anyways, I'm just calling createResource with a fetch on it and returning it's json. But, for any reason, that fn is returning undefined, even when the data is properly fetched("tested" by logging the json). Code:
const useFetch = <T>(p: UseFetchParams) => {
const [url] = createSignal(createUrl(p));

const [data] = createResource<T>(async () => {
return await fetch(url()).then(async (res) => (await res.json()) as T);
});

return { data, didFetch: data() !== undefined };
};
const useFetch = <T>(p: UseFetchParams) => {
const [url] = createSignal(createUrl(p));

const [data] = createResource<T>(async () => {
return await fetch(url()).then(async (res) => (await res.json()) as T);
});

return { data, didFetch: data() !== undefined };
};
105 replies