Created
January 5, 2022 06:08
-
-
Save kgravenreuth/dfcc8e7bb94a4285a3eef92e86de6830 to your computer and use it in GitHub Desktop.
Cloudbet Market Helper with API Key
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
//App.js | |
import "./styles.css"; | |
import React from "react"; | |
import { Locale, getSportsName } from "@cloudbet/market-helper"; | |
function getSport(sport, apiKey) { | |
return fetch(`https://sports-api.cloudbet.com/pub/v2/odds/sports/${sport}`, { | |
headers: { | |
"X-Api-Key": "", | |
"cache-control": "max-age=600" | |
} | |
}); | |
} | |
const sports = ["soccer", "basketball", "american-football"]; | |
export default function App() { | |
const [sport, setSport] = React.useState(sports[0]); | |
const [loading, setLoading] = React.useState(false); | |
React.useEffect(() => { | |
if (!sport) { | |
return; | |
} | |
setLoading(true); | |
getSport(sport) | |
.then((response) => { | |
setLoading(false); | |
return response.json(); | |
}) | |
}, [sport]); | |
return ( | |
<div className="App"> | |
<div> | |
<label for="sport">Sport</label> | |
<select value={sport} onChange={(e) => setSport(e.target.value)}> | |
{sports.map((s) => ( | |
<option value={s}>{getSportsName(s, Locale.ko)}</option> | |
))} | |
</select> | |
</div> | |
{loading && <Loading />} | |
</div> | |
); | |
} | |
function Loading() { | |
return Loading...; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment