Skip to content

Commit

Permalink
Challenge and Code: Ten More Jokes
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Oct 19, 2022
1 parent a12f7ba commit a65d95f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 24 deletions.
Binary file modified portfolio/.parcel-cache/data.mdb
Binary file not shown.
83 changes: 64 additions & 19 deletions portfolio/dist/index.975ef6c8.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion portfolio/dist/index.975ef6c8.js.map

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions portfolio/src/components/Jokes.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import React, { Component } from 'react';

const Joke = ({ joke: { setup, punchline } }) => (
<p style={{ margin: 20 }}>{setup} <em>{punchline}</em></p>
);

class Jokes extends Component {
state = { joke: {} };
state = { joke: {}, jokes: [] };

componentDidMount() {
fetch('https://official-joke-api.appspot.com/random_joke')
.then(response => response.json())
.then(json => this.setState({ joke: json }));
}

render() {
const { setup, punchline } = this.state.joke;
fetchJokes = () => {
fetch('https://official-joke-api.appspot.com/random_ten')
.then(response => response.json())
.then(json => this.setState({ jokes: json }));
}

render() {
return (
<div>
<h2>Highlighted Joke</h2>
<p>{setup} <em>{punchline}</em></p>
<Joke joke={this.state.joke} />
<hr />
<h3>Want ten new jokes?</h3>
<button onClick={this.fetchJokes}>Click me!</button>
{this.state.jokes.map(joke => (<Joke key={joke.id} joke={joke} />))}
</div>
)
}
Expand Down

0 comments on commit a65d95f

Please sign in to comment.