MCPcopy
hub / github.com/zcreativelabs/react-simple-maps / useGeographies

Function useGeographies

src/components/useGeographies.js:13–50  ·  view source on GitHub ↗
({ geography, parseGeographies })

Source from the content-addressed store, hash-verified

11} from "../utils"
12
13export default function useGeographies({ geography, parseGeographies }) {
14 const { path } = useContext(MapContext)
15 const [output, setOutput] = useState({})
16
17 useEffect(() => {
18 if (typeof window === `undefined`) return
19
20 if (!geography) return
21
22 if (isString(geography)) {
23 fetchGeographies(geography).then((geos) => {
24 if (geos) {
25 setOutput({
26 geographies: getFeatures(geos, parseGeographies),
27 mesh: getMesh(geos),
28 })
29 }
30 })
31 } else {
32 setOutput({
33 geographies: getFeatures(geography, parseGeographies),
34 mesh: getMesh(geography),
35 })
36 }
37 }, [geography, parseGeographies])
38
39 const { geographies, outline, borders } = useMemo(() => {
40 const mesh = output.mesh || {}
41 const preparedMesh = prepareMesh(mesh.outline, mesh.borders, path)
42 return {
43 geographies: prepareFeatures(output.geographies, path),
44 outline: preparedMesh.outline,
45 borders: preparedMesh.borders,
46 }
47 }, [output, path])
48
49 return { geographies, outline, borders }
50}

Callers 1

Geographies.jsFile · 0.85

Calls 6

isStringFunction · 0.90
fetchGeographiesFunction · 0.90
getFeaturesFunction · 0.90
getMeshFunction · 0.90
prepareMeshFunction · 0.90
prepareFeaturesFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…