-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Math magicians: fetch data from API #4
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a4bdcf7
Update DisplayQuote.js
HossainAraf eca2467
Update Quote display style
HossainAraf fe32b2a
Update functional components to display quote
HossainAraf 3705862
Update style for quotes
HossainAraf 8a9d21d
Update Quote component
HossainAraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
* { | ||
margin: auto; | ||
margin: 0; | ||
} | ||
|
||
#logo { | ||
margin: 3%; | ||
margin-left: 3%; | ||
margin-top: 3%; | ||
width: 4%; | ||
} | ||
|
||
.App { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 3%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import '../styles/display-quote.css'; | ||
|
||
const JokeComponent = () => { | ||
const [joke, setJoke] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState(false); | ||
|
||
useEffect(() => { | ||
const myAPIKey = 'Ixgm2cYnlo7wGSvmiMQCVvfUJ6kVeTvgNZShaXEC'; | ||
const apiURL = 'https://api.api-ninjas.com/v1/dadjokes?limit=1'; | ||
|
||
const options = { | ||
method: 'GET', | ||
headers: { 'X-Api-Key': myAPIKey }, | ||
}; | ||
|
||
const fetchData = async () => { | ||
try { | ||
const response = await fetch(apiURL, options); | ||
const data = await response.json(); | ||
setJoke(data[0].joke); | ||
} catch (error) { | ||
setError(true); | ||
} | ||
setLoading(false); | ||
}; | ||
|
||
fetchData(); // Call the function to fetch data when the component mounts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, []); | ||
return ( | ||
<div> | ||
{loading && <p>Loading...</p>} | ||
{error && ( | ||
<div> | ||
<p>Error:</p> | ||
{/* <p>{error}</p> */} | ||
</div> | ||
)} | ||
{joke && ( | ||
<div id="display-joke"> | ||
<h4>Joke of the Day:</h4> | ||
<p>{joke}</p> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default JokeComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
#display-joke { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
} | ||
|
||
#display-joke h4 { | ||
color: #fff; | ||
font-family: cursive; | ||
} | ||
|
||
#display-joke p { | ||
color: #004; | ||
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; | ||
margin-top: 1.5%; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.