SolidJSS
SolidJSโ€ข3y agoโ€ข
3 replies
dalton

createResource not fetching on page change

Im using solid and solid router, I have a dynamic route I want to fetch data based on the id. When i go to a route with a different id it just shows the originally resource and not refetching. /category/1 --> change to /category/2 shows the data for 1.
const fetchLibraries = async (id: string) => {
  const response = await fetch(
    `http://localhost:4000/api/library/category/${id}`
  );
  return response.json();
};

function Category() {
  const params = useParams();
  const [libraries] = createResource(params.id, fetchLibraries);
  return (
    <For each={libraries()}>
      {(library: Library) => (
        <LibraryCard
          name={library.name}
          description={library.description}
          repoURL={library.repoURL}
        />
      )}
    </For>
  );
}

export default Category;
Was this page helpful?