two List in the same component
i using the useList, but i need use again in the same component how can i do it?
useList hook multiple times in the same component. Each useList hook can be used to fetch data from a different resource or the same resource with different parameters. Here's an example:useList hook fetches data from the "products" resource, and the second useList hook fetches data from the "categories" resource. You can adjust the resources and parameters as needed for your application.useListuseListuseListuseListimport { useList, HttpError } from "@refinedev/core";
interface IProduct {
id: number;
name: string;
material: string;
}
const ProductList: React.FC = () => {
const { data: data1, isLoading: isLoading1, isError: isError1 } = useList<IProduct, HttpError>({
resource: "products",
});
const { data: data2, isLoading: isLoading2, isError: isError2 } = useList<IProduct, HttpError>({
resource: "categories",
});
const products = data1?.data ?? [];
const categories = data2?.data ?? [];
if (isLoading1 || isLoading2) {
return <div>Loading...</div>;
}
if (isError1 || isError2) {
return <div>Something went wrong!</div>;
}
// Render your products and categories here
};