Browse Source

Create hook to call new generators api

Kirk Trombley 4 years ago
parent
commit
c4f2e5cbce
1 changed files with 20 additions and 0 deletions
  1. 20 0
      client/src/hooks/useAvailableGenerators.jsx

+ 20 - 0
client/src/hooks/useAvailableGenerators.jsx

@@ -0,0 +1,20 @@
+import { useEffect, useState } from "react";
+import { getGenerators } from "../domain/apiMethods";
+
+
+const useAvailableGenerators = () => {
+  const [state, setState] = useState(null);
+
+  useEffect(() => {
+    const lookup = async() => {
+      const { generators } = await getGenerators();
+      const generatorMap = Object.fromEntries(generators.map(({ generationMethod, countryLocks }) => [generationMethod, countryLocks]));
+      setState(generatorMap);
+    }
+    lookup();
+  }, []);
+
+  return state;
+};
+
+export default useAvailableGenerators;