I am using useEffect hook to call my data api and AgGrid onGridReady to populate the data. problem i have is when i use setRowData first time to populate AgGrid, orderData is null.problem seem to have that setRowData get called before order data is fetched via api and set. (i dont want to use timeout option as it's not a feasible option in my case)
is there a way that onGridReady setRowData can be called after my grid is loaded (post hook is called). currently it only works if i refresh (i have a refresh function that call gridApi.setRowData again and this time it works)
this is my orderdata states and ag-grid-react component
const [orderData, setOrderData] = useState([]);
const [gridApi, setGridApi] =useState(null);
const onGridReady = params => {
setGridApi(params.api);
params.api.setRowData(orderData);//this is null which i want not null
params.api.sizeColumnsToFit();
};
hook to fetch data and retrieveOrderByBondID will set the orderDataState
useEffect(() => {
retrieveOrdersByBondId(props.Id);
}, [props.Id]);
<AgGridReact
enableCellChangeFlash={true}
columnDefs={columns}
onGridReady={onGridReady}
/>