Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
// create your App component here
import React, { useState, useEffect } from 'react';

const App = () => {
const [dogImage, setDogImage] = useState(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
fetch('https://dog.ceo/api/breeds/image/random')
.then(response => response.json())
.then(data => {
setDogImage(data.message);
setLoading(false);
})
.catch(error => {
console.error('Error fetching the dog image:', error);
setLoading(false);
});
}, []);

return (
<div>
{loading ? (
<p>Loading...</p>
) : (
<img src={dogImage} alt="A Random Dog" />
)}
</div>
);
};

export default App;