Sfoglia il codice sorgente

Add Table to insect container

Tatiana Inama 6 anni fa
parent
commit
a61a3fc187
2 ha cambiato i file con 20 aggiunte e 3 eliminazioni
  1. 19 2
      app/src/Insects/index.tsx
  2. 1 1
      app/src/services/Api.ts

+ 19 - 2
app/src/Insects/index.tsx

@@ -1,8 +1,25 @@
-import React, { FunctionComponent } from 'react';
+import React, { FunctionComponent, useState, useEffect } from 'react';
+import { Insect } from 'types';
+import { getInsects } from 'services/Api';
+import Table from 'components/Table';
 
 const InsectTable: FunctionComponent = () => {
+  const [ data, setData ] = useState<Insect[]>([]);
+  
+  const fetchData = async () => {
+    const response = await getInsects()
+    setData(response)
+  }
+  
+  useEffect(() => {
+    fetchData();
+  }, [])
+  
   return (
-    <div>insect</div>
+    <>
+      <Table data={data}></Table>
+    </>
+  
   )
 };
 

+ 1 - 1
app/src/services/Api.ts

@@ -3,7 +3,7 @@ import { Fish, Insect } from 'types';
 
 export const getFishes = (): Promise<Fish[]> => Axios.get(`${process.env.REACT_APP_API}/data/fishes.json`).then(result => result.data);
 
-export const getInsects = (): Promise<Insect[]> => Axios.get(`${process.env.REACT_APP_API}/insects`).then(result => result.data);
+export const getInsects = (): Promise<Insect[]> => Axios.get(`${process.env.REACT_APP_API}/data/insects.json`).then(result => result.data);
 
 export default {
   getFishes,