My script is like this below,
After api fetch the items, I want to rerender component and make EnhancedTable
appered.
However this script, api fetch success, but EnhancedTable is not appeared.
response.data returns correct data but, re-render is not executed.
Where am I wrong?
const MetaPanel = (props) =>{
const [drawingItems,setDrawingItems] = React.useState([]);
useEffect(() => {
console.log("File List");
var formData = new FormData();
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
axios.defaults.xsrfCookieName = "csrftoken";
axios.defaults.withCredentials = true;
axios.get(`/api/drawings/`)
.then(function (response) {
console.log(response.data);
setDrawingItems(response.data);
})
.catch(function (response) {
console.log(response);
});
},[]);
return (
<div>
<div>
<p>FileList</p>
{drawingItems.length != 0 &
<EnhancedTable data={drawingItems}></EnhancedTable>
}
</div>
</div>
);
}