How to show Fakestore API data in getBootstrap card component using react js
Fetch Data from the FakeStore API
Use fetch
or axios
to get data from the FakeStore API. Here's an example using the useEffect
and useState
hooks.
Explanation
State and Fetching Data:
useState
initializes an empty array for products.useEffect
fetches data from the FakeStore API when the component mounts and updates the state.
Bootstrap Grid System:
- Use
row
andcol-md-4
for a responsive grid layout.
- Use
Bootstrap Cards:
- Each product is displayed inside a
card
with an image, title, description, and price. - The description is truncated for brevity.
- Each product is displayed inside a
Styling:
- The image style ensures proper scaling within the card.
- Cards are responsive and look good on all screen sizes.
Run the App
Start the app with npm start
. You should see a grid of Bootstrap cards
displaying products from the FakeStore API.