DataTable: in controlled pagination mode onPage always called initially with first=0 #3489
Labels
React 18/19
Issue or pull request is *only* related to React 18/19
Type: Bug
Issue contains a defect related to a specific component.
Milestone
Describe the bug
When trying to control pagination in
DataTable
(settingrows=
,first=
andonPage=
) in React v18 development mode and under<React.StrictMode>
, there is an initialonPage
call without any user interaction. This call ignores the value offirst=
prop and signalsfirst=0
.In effect, the page is always reset to the first one.
The behavior is not consistent with production build, where this doesn't happen. So, it is hard to implement a reliable workaround (such as: ignoring the first
onPage
call).Probably related to React v18 changes to
useEffect()
in development mode.Reproducer
https://codesandbox.io/s/primereact-test-forked-3kh0xq?file=/src/App.jsx
PrimeReact version
8.6.1
React version
18.x
Language
ALL
Build / Runtime
Create React App (CRA)
Browser(s)
No response
Steps to reproduce the behavior
useState()
).Expected behavior
When I pass
first={2}
, I expectonPage
not to be called without user interaction and if (for some reason) it must be called, it should be called with{first: 2}
as an argument and not{first: 0}
.The text was updated successfully, but these errors were encountered: