Skip to content

Instantly share code, notes, and snippets.

@randyphoa
Last active November 7, 2022 18:57
Show Gist options
  • Save randyphoa/e2222c76db8b6730d283750e6977fc5a to your computer and use it in GitHub Desktop.
Save randyphoa/e2222c76db8b6730d283750e6977fc5a to your computer and use it in GitHub Desktop.
Get accident data in React JS app
const getAccidentData = (countries) => {
const payload = {
input_data: [{
values: [{
ACTION: "GET_ACCIDENT_DATA",
PARAMS: { COUNTRY: countries.map(x => x.toUpperCase()) }
}]
}]
};
axios.post(URL, payload).then((response) => {
const fields = response.data.fields;
const values = response.data.values;
const data = values.map((x) => Object.fromEntries(zip(fields, x)));
setClusterData([]);
setPredictionData([]);
setAccidentData(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment