// this is the fetcher func
const fetchData = async (id: string) => {
const response = await fetch(`/api/xyz/${id}`);
return response.json();
};
export const Page = () => {
const params = useParams();
// A: this does not update on route change
const [data] = createResource(params.id, fetchData);
// B: this works
const [data] = createResource(() => params.id, fetchData);
...
return <SomeDataComponent data={data()} />
}
// this is the fetcher func
const fetchData = async (id: string) => {
const response = await fetch(`/api/xyz/${id}`);
return response.json();
};
export const Page = () => {
const params = useParams();
// A: this does not update on route change
const [data] = createResource(params.id, fetchData);
// B: this works
const [data] = createResource(() => params.id, fetchData);
...
return <SomeDataComponent data={data()} />
}