I am using react query to fetch data from API. I want to fetch a single product data, and render a component with its data. The problem is that the react query ist working at all. Help me please.
This is the react query ...what is wrong here can anyone help.
export async function fetchProductById(id) {
return fetch(`https://fakestoreapi.com/products/${id}`).then((response) =>
response.json()
);
}
export function useProduct({id}) {
return useQuery({
queryKey: ["products", id],
queryFn: () => fetchProductById(id),
});
}
In my component:
In my component:
import React from 'react'
import { useParams } from "react-router-dom";
import { useProduct } from '../fetch/api';
const ProductDescription = () => {
const { id } = useParams();
const {data} = useProduct(id);
console.log(data);