DEV Community

Nikolay Kozenko
Nikolay Kozenko

Posted on

Help me how to use new hook 'use' to fetch data?

Here is my code: import './App.css'
import axios from 'axios'
import {Suspense, use} from "react"
interface Product {
id: number;
title: string;
price: number;
description: string;
category: string;
image: string;
rating: {
rate: number;
count: number;
};
}
function App() {

const product = use(axios.get('https://fakestoreapi.com/products/1'))

return (


Мои данные:
Loading...}>


{product.title}

  <p><strong>Price:</strong> ${product.price}</p>
  <p><strong>Description:</strong> {product.description}</p>
  <p><strong>Category:</strong> {product.category}</p>
  <p>
    <strong>Rating:</strong> {product.rating.rate} ({product.rating.count} reviews)
  </p>
</div>

</Suspense>
</div>

);
}

export default App; How to receive data?

Top comments (0)