I am currently building a web application with React with TypeScript. I am trying to fetch a custom-built API. However, it is returning too many of them. How do I access the whole API to do filtering of them after storing them in a state?
import React, { useEffect, useState } from "react";
import axios from "axios";
interface Invoice {
id: number;
customer_id: number;
customer_name: string;
date: string;
total_invoice: number;
total_margin: number;
region: string;
invoice_lines: [
{
product_id: number;
product_name: string;
unit_price: number;
quantity: number;
total_line: number;
total_margin: number;
}
];
}
function App() {
const [data, setData] = useState<Invoice[]>([]);
useEffect(() => {
axios.get<Invoice[]>("http://localhost:3001/api/invoices").then(res => setData(res.data));
console.log(data);
}, []);
return (
<React.Fragment>
<header>
<h1>Hello</h1>
</header>
<main>
{data.map(d => (
<p key={d.id}>{d.customer_name}</p>
))}
</main>
</React.Fragment>
);
}
export default App;