Skip to content

Commit

Permalink
good useeffect process working
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Leopold committed Jun 17, 2021
1 parent 65d5d96 commit bf137cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class App extends Component {
}

render() {
console.log("App rendered boi");
return (
<div className="App">
<header>
Expand Down
22 changes: 19 additions & 3 deletions src/TestCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import axios from "axios"

const TestCall = (props) => {

const [authState, changeAuthState] = useState(false)

useEffect( () => {
if (props.oAuth) {
changeAuthState(true)
}
})

const [flights, refreshFlights] = useState()

let grabFlights = async () => {
Expand All @@ -12,14 +20,15 @@ const TestCall = (props) => {
console.log(props.oAuth, "OAUTH")
let testFlights = await axios({
method: "GET",
url: `https://test.api.amadeus.com/v2/shopping/flight-offers/?originLocationCode="SFO"&destinationLocationCode="JFK"&departureDate="2021-08-15"&returnDate="2021-08-22"`,
url: `https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=SFO&destinationLocationCode=JFK&departureDate=2021-08-15&returnDate=2021-08-22&adults=1`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Bearer ${props.oAuth}`,
},
})

refreshFlights(testFlights)
return testFlights

} catch (err) {

Expand All @@ -29,10 +38,17 @@ const TestCall = (props) => {

}

grabFlights().then( result => console.log(result) )
useEffect( () => {
if (authState) {
grabFlights()
}
}, [authState])

useEffect( () => console.log(flights), [flights])

return (
<div>
{flights && <p>{JSON.stringify(flights.data.data[0])}</p>}
</div>
)

Expand Down

0 comments on commit bf137cf

Please sign in to comment.