I am using AgGrid for React and I am using class-style react components - not functional components.
My goal is to render the cellStyle based on props conditions.
However, when I want to render it, it renders without even the props are loaded.
How can I fix this?
You probably want to call GridApi.refreshCells() to apply the change after updating the column's cellStyle:
const columnDefs = React.useMemo(
() => [
{...}
{
headerName: "Age",
field: "age",
cellStyle: props.styles
? { backgroundColor: "pink" }
: { backgroundColor: "white" }
}
],
[props.styles]
);
React.useEffect(() => {
gridApi?.refreshCells({ force: true });
}, [props.styles]);