Skip to content

Instantly share code, notes, and snippets.

@ievgenk
Created February 13, 2019 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ievgenk/bc18f0a44a31676e4888d11d80c418da to your computer and use it in GitHub Desktop.
Save ievgenk/bc18f0a44a31676e4888d11d80c418da to your computer and use it in GitHub Desktop.
React Hook Example
import React, { useEffect, useState } from 'react';
import Map from './components/Map';
import axios from 'axios';
const mapBoxToken: string =
'apikey';
const getInitialMapPoint = (token: string) => {
axios
.get(
`https://api.mapbox.com/geocoding/v5/mapbox.places/oakridge+vancouver+bc+canada.json?access_token=${mapBoxToken}`
)
.then(data => {
console.log(data);
});
};
const App: React.FunctionComponent = () => {
const [initCoordinates, setInitCoordinate] = useState([0, 0]);
useEffect(() => {
getInitialMapPoint(mapBoxToken);
});
return (
<div>
<Map />
</div>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment