Skip to content

Instantly share code, notes, and snippets.

View vitorfranca's full-sized avatar

Vitor França vitorfranca

  • ThoughtWorks
  • San Francisco, California, US
  • 17:45 (UTC -07:00)
View GitHub Profile
@vitorfranca
vitorfranca / useFetch.js
Created June 17, 2020 17:53
React Hook - useFetch with loading, error and refetch function
import { useState, useEffect } from 'react'
export const useFetch = (url) => {
const [data, setData] = useState(null)
const [isLoading, setIsLoading] = useState(false)
const [hasError, setHasError] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const [refetchIndex, setRefetchIndex] = useState(0)
const refetch = () => setRefetchIndex((prevRefetchIndex) => prevRefetchIndex + 1)
@vitorfranca
vitorfranca / distanceBetweenCoordinates.js
Created August 30, 2018 18:48
Calculates the distance in Km between two earth coordinates
function degreesToRadians(degrees) {
return degrees * Math.PI / 180;
}
function distanceInKmBetweenEarthCoordinates(lat1, lon1, lat2, lon2) {
var earthRadiusKm = 6371;
var dLat = degreesToRadians(lat2-lat1);
var dLon = degreesToRadians(lon2-lon1);

Keybase proof

I hereby claim:

  • I am vitorfranca on github.
  • I am vitorfranca (https://keybase.io/vitorfranca) on keybase.
  • I have a public key ASBSZ7HGR4GYicMcJjee7YfghK_iDiLMAMNpkyMEBFgH2Ao

To claim this, I am signing this object: