Skip to content

add meetup component with API call #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
37 changes: 37 additions & 0 deletions src/components/meetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { Fragment, useState, useEffect } from "react"

const MeetUp = () => {
const [events, setEvents] = useState([])

const corsAPI = "https://cors-anywhere.herokuapp.com/"
const meetupURL =
"https://www.meetup.com/Syracuse-Software-Development-Meetup/events/json/"

useEffect(() => {
fetch(corsAPI + meetupURL, {
Copy link
Member

@1egoman 1egoman Jul 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to url encode meetupURL in this situation: corsAPI + encodeURIComponent(meetupUrl). I'm not 100% sure on this, it's just a hunch and in practice it may not matter.

method: 'GET',
headers: { 'X-Requested-With': 'XMLHttpRequest' },
}).then(res => {
res.json().then((res) => {
console.log(res)
setEvents(res)
})
})
}, [])

return (
<div>
<h1>Upcoming Events</h1>

{events &&
events.map((event, index) =>
<Fragment key={index}>
<p>{event.title}</p>
<p>{event.descr}</p>
</Fragment>
)}
</div>
)
}

export default MeetUp