Skip to content

Instantly share code, notes, and snippets.

@hiiamyes
Last active April 5, 2019 18:40
Show Gist options
  • Select an option

  • Save hiiamyes/c27a0986ad1047c0bfd4c8459f7d2879 to your computer and use it in GitHub Desktop.

Select an option

Save hiiamyes/c27a0986ad1047c0bfd4c8459f7d2879 to your computer and use it in GitHub Desktop.
data-visualization-2-graphql
import React, { useState, useEffect } from "react";
import axios from "axios";
import { draw } from "./chart";
const App = () => {
const [rainfalls, setRainfalls] = useState(null);
useEffect(() => {
async function get() {
const {
data: {
data: { station }
}
} = await axios.request({
method: "POST",
url: "http://localhost:4000",
data: {
query: `
query{
station(id: "466900") {
id
rainfalls {
date
value
}
}
}`
}
});
const { rainfalls } = station;
setRainfalls(rainfalls);
draw({ rainfalls });
}
if (!rainfalls) get();
});
return <div className="chart" />;
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment