You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

producDataRequest.ts 523B

1234567891011121314151617181920212223
  1. import apiEndpoints from '../apiEndpoints';
  2. interface SingleProductResponse {
  3. message: string;
  4. product: object;
  5. similarProducts: Array<object>;
  6. }
  7. export const getProductData = async (
  8. productId: string
  9. ): Promise<SingleProductResponse> => {
  10. const response = await fetch(
  11. `http://localhost:3000${apiEndpoints.products}/${productId}`
  12. );
  13. const data: SingleProductResponse = await response.json();
  14. if (!response.ok) {
  15. throw new Error(data.message || 'Something went wrong!');
  16. }
  17. return data;
  18. };