I currently am trying out the Handsontable react plugin. However I cannot get the table to rerender when the state changes the data thats in the table.
const [communities, setCommunities] = React.useState({
data: [],
licenseKey: "non-commercial-and-evaluation",
colHeaders: true,
rowHeaders: true,
width: "100%",
height: "300",
});
const useComponentDidMount = func => useEffect(func, []);
useComponentDidMount(() => fetchData())
const fetchData = () => {
fetch('http://localhost:8080/v1/graphql', {
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `query { communities {id budget_neighborhood_id division_id code name city state county city_of_clerk is_active} }`,
}),
}).then(response => {
return response.json()
}).then(responseAsJson => {
let updatedCommunities = {...communities};
updatedCommunities.data = responseAsJson.data.communities;
setCommunities(updatedCommunities);
});
}
console.log(communities);
return (
<div>
<HotTable id="hot" settings={communities} />
</div>
);
When I load the page it shows a table with just the rows headers listed 1, 2 and wont load the changes to the state for data. I looked in the console log and the initial data set is none, then it gets 2 rows with data however only the two rows are displayed and no data. When I click a button on the page to display something else it will rerender the table as expected to show all the data. Why is the state changes not populating to the tables?