I am working in a jhipster application, with data coming from postgress sql. The api is http://localhost:8080/api/agreements and I am trying to display the data in a react material table but I am getting this error "Invalid prop data supplied to MaterialTable, expected one of type [function]" on my console after writing my functions.
Let me walk you through my codes below:
Inside the React component
const apiUrl = 'http://localhost:8080/api/agreements';
const [data, setData] = useState([]);
useEffect(() => {
getAgreementsData();
}, []);
const getAgreementsData = () => {
fetch(apiUrl)
.then(res => res.json())
.then(res => setData(res));
};
Inside the JSX
<MaterialTable
title="Agreements"
data={data}
columns={columns}/>
The columns are displaying but the data is not.
And this warning is on the console " GET http://localhost:8080/api/agreements 401 (Unauthorized)"