mirror of
https://github.com/gosticks/react-table.git
synced 2026-06-29 01:20:02 +00:00
fix: fixed disablePageResetOnDataChangeRef dependencies
disablePageResetOnDataChangeRef will no longer trigger page resets when changed
This commit is contained in:
@@ -230,17 +230,17 @@ function App() {
|
||||
|
||||
const [data, setData] = React.useState(() => makeData(20))
|
||||
const [originalData] = React.useState(data)
|
||||
const [skipPageReset, setSkipPageReset] = React.useState(false)
|
||||
|
||||
// We need to keep the table from resetting the pageIndex when we
|
||||
// Update data. So we can keep track of that flag with a ref.
|
||||
const skipPageResetRef = React.useRef(false)
|
||||
|
||||
// When our cell renderer calls updateMyData, we'll use
|
||||
// the rowIndex, columnID and new value to update the
|
||||
// original data
|
||||
const updateMyData = (rowIndex, columnID, value) => {
|
||||
// We also turn on the flag to not reset the page
|
||||
skipPageResetRef.current = true
|
||||
setSkipPageReset(true)
|
||||
setData(old =>
|
||||
old.map((row, index) => {
|
||||
if (index === rowIndex) {
|
||||
@@ -258,7 +258,7 @@ function App() {
|
||||
// so that if data actually changes when we're not
|
||||
// editing it, the page is reset
|
||||
React.useEffect(() => {
|
||||
skipPageResetRef.current = false
|
||||
setSkipPageReset(false)
|
||||
}, [data])
|
||||
|
||||
// Let's add a data resetter/randomizer to help
|
||||
@@ -272,7 +272,7 @@ function App() {
|
||||
columns={columns}
|
||||
data={data}
|
||||
updateMyData={updateMyData}
|
||||
disablePageResetOnDataChange={skipPageResetRef.current}
|
||||
disablePageResetOnDataChange={skipPageReset}
|
||||
/>
|
||||
</Styles>
|
||||
)
|
||||
|
||||
@@ -49,8 +49,15 @@ function useMain(instance) {
|
||||
|
||||
const isPageIndexMountedRef = React.useRef()
|
||||
|
||||
// Bypass any effects from firing when this changes
|
||||
const disablePageResetOnDataChangeRef = React.useRef()
|
||||
disablePageResetOnDataChangeRef.current = disablePageResetOnDataChange
|
||||
|
||||
safeUseLayoutEffect(() => {
|
||||
if (isPageIndexMountedRef.current && !disablePageResetOnDataChange) {
|
||||
if (
|
||||
isPageIndexMountedRef.current &&
|
||||
!disablePageResetOnDataChangeRef.current
|
||||
) {
|
||||
setState(
|
||||
old => ({
|
||||
...old,
|
||||
@@ -60,7 +67,7 @@ function useMain(instance) {
|
||||
)
|
||||
}
|
||||
isPageIndexMountedRef.current = true
|
||||
}, [setState, rowDep, filters, groupBy, sortBy, disablePageResetOnDataChange])
|
||||
}, [setState, rowDep, filters, groupBy, sortBy])
|
||||
|
||||
const pageCount = manualPagination
|
||||
? userPageCount
|
||||
|
||||
Reference in New Issue
Block a user