'What is a prevRowCountState in mui-data-grid?
Server pagination, I understand the logic but can't figure out how does the grid know the value of prevRowCountState
. Is it a undocumented thing, prefix a const/property with prev
then the grid knows it's for the previous value?
const [rowCountState, setRowCountState] = React.useState(rowCount);
React.useEffect(() => {
setRowCountState((prevRowCountState) =>
rowCount !== undefined ? rowCount : prevRowCountState,
);
}, [rowCount, setRowCountState]);
<DataGrid rowCount={rowCountState} />;
Solution 1:[1]
set<Something>
is action of setState
method for Something
. When supplying an argument in a form of function such as set<Something>((whatever)=> {...});
, whatever is the previous state of something.
References:
- React's State, starting "To fix it, use a second form of setState()..."
- Geek to Geek, example 4,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeb50 |