I fetch data from API and pass it to Table component like this:
function MainSectionOrganization() {
const [obj, setObj] = useState([]);
useEffect(() => {
fetch('http://127.0.0.1:5000/getCompanies')
.then((response) => {
return response.json();
}).then((data) => {
setObj(data);
})
}, []);
return (
<Table data={obj} />
)
}
Then, in Table component, I try to do console.log for props.data[0] and I see data in Chrome terminal correctly.
import React from 'react';
import './Table.css';
import { useTable } from 'react-table';
function Table(props) {
console.log(props.data[0]);
...
However, when I try to access any properties of the object, for example console.log(props.data[0].OU01_Code), I encounter an error Cannot read property '...' of undefined
I see many people have solution with class component, but for some reason I need to use function component. Can you help me on this one ?
