Hi again. How can I pass multiple values into a createResource? I tried to create an object and passing it to the fetcher, but I get an undefined value.
This is the code that should get some data from a platform (like Crates or NPM) and a package.
// --- Package.tsx
const params = useParams(); // for example /crates/tokio
const data = { platform: params.platform, pkg: params.pkg };
const [pkg] = createResource(() => data, fetch); // Expected an object, got undefined
// --- fetch.ts
export const fetch = async (data: { platform: platform; pkg: string }): Promise<null | pkg> => {
const workers = [crates];
try {
return await workers.filter(e => e.platform == data.platform)[0].data(data.pkg); // This calls a function that makes a request, works fine.
} catch (e) {
return null;
}
};
I don't know if I'm doing something wrong. If you want the full code, ping me and I'll pass the repo. Thanks