I have problem with pass props to external components in next.js I have problem with line
const { isLoading, data, error } = useQuery("products", getProducts(1));
getProducts(1)) -> How I should pass props to this component?
page:
import { useQuery } from "react-query";
import { getProducts } from "../components/task-1/getProducts-0";
export const ProductsPage = () => {
const { isLoading, data, error } = useQuery("products", getProducts(1));
if (isLoading) {
return <div>Loading...</div>;
}
if (!data || error) {
return <div>Error#!</div>;
}
return <>...</>;
};
export default ProductsPage;
component:
export const getProducts = async (id: number) => {
const rest = await fetch(
`https://fakestoreapi.com/products/${id}`
);
const data: ProductApi[] = await rest.json();
return data;
};
interface ProductApi {
id: number;
title: string;
price: number;
description: string;
category: string;
image: string;
rating: Rating;
}
interface Rating {
rate: number;
count: number;
}