SolidJSS
SolidJSโ€ข2y agoโ€ข
2 replies
markus

CreateResource does not update as expected

I'm new to Solid, please forgive me if that is a total dummy question.

I'm using solid router and I have this code:

// 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()} />

}


According to the docs, useParams "retrieves a reactive object containing the current route path paramteres as defined in the Route".

I'd like to understand why version A does not cause <SomeDataComponent> to update when the route changes, but version B does.
Was this page helpful?