feat(pbf): add axios get call to home page
This commit is contained in:
parent
f820f3e8da
commit
bf9d0029cf
|
@ -1,12 +1,35 @@
|
|||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import axios from 'axios';
|
||||
import Hello from '../components/hello';
|
||||
import '../style.css';
|
||||
const Home = () => {
|
||||
/*storage*/
|
||||
const [vehPos, setVehPos] = useState({});
|
||||
/*fetch vehPost in a JavaScript function*/
|
||||
const getVehPos = async () => {
|
||||
try {
|
||||
/*TODO handle errors: https://www.valentinog.com/blog/await-react/*/
|
||||
let url = 'https://soll.vbn.de/vehicle-positions';
|
||||
const res = await axios.get(url);
|
||||
//TODO remove debugging
|
||||
if (res.data) {
|
||||
console.log('getVehPos() res.data: ', res.data);
|
||||
} else {
|
||||
console.error('getVehPos() res.data unavailable ');
|
||||
}
|
||||
/*set state*/
|
||||
setVehPos(res.data);
|
||||
} catch (err) {
|
||||
console.error('err.message: ' + err.message);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2>Home</h2>
|
||||
<h3>(React.js Lambda Function Component)</h3>
|
||||
<Hello msg="Hello World!" />
|
||||
<button onClick={getVehPos}>getVehPos</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue