onFetchData fires at the wrong time
See original GitHub issueWhat version of React-Table are you using?
"react-table": "^6.8.6",
What bug are you experiencing, or what feature are you proposing?
I’m using a completely controlled component, and redux to hold my pages. When we click “next”, onFetchData fires too early and it fetches the same page we already currently have.
Not sure why onFetchData is firing when the page isn’t changing, it seems to always fire if we just click “next” or “previous”.
<ReactTable
data={this.state.data}
filterable={true}
pages={this.state.numPages}
columns={columns}
footerClassName={css(styles.tableFooter)}
defaultPageSize={folder.options.pageSize}
page={folder.options.page}
onPageSizeChange={(pageSize) => {
folderActions.updateOptions({
pageSize: pageSize,
page: (folder.options.pageSize * this.state.numPages) > (pageSize * folder.options.page) ? folder.options.page : 0
});
}}
onPageChange={(pageIndex) => {
folderActions.updateOptions({page: pageIndex})
}}
minRows={0}
manual
onFetchData={(state, instance) => {
this.pagination(state);
}}
/>
Currently don’t have a sandbox but can provide when needed.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
onFetchData fires at the wrong time · Issue #1072 - GitHub
I'm using a completely controlled component, and redux to hold my pages. When we click "next", onFetchData fires too early and it fetches...
Read more >A way to trigger onFetchData in ReactTable - Stack Overflow
in documentation I can find server-side section with says that onFetchData is called at componentDidMount and any time sorting, ...
Read more >react-table - npm
Something went wrong. Illustration of wombats. The package file size seems to be too large or the last published date is too old....
Read more >DynamicForm (Smart GWT LGPL Edition API 13.0p (2022-12 ...
If the user rolls over an item, how long a delay before we fire any hover action / show a hover for that...
Read more >Falcon Sandbox v8.31 © Hybrid Analysis
(\d{1})/, m, t; if (!p.test(text)) { console.log('wrong time format. ... onFetchData)); topic.subscribe('clearAllData', lang.hitch(this, this.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So I looked into your guys’ code, and it seems that the issue is this:
https://github.com/react-tools/react-table/blob/master/src/methods.js#L431-L439
Even though I’ve defined onPageChange and my own page prop, this onPageChange, which then calls this:
https://github.com/react-tools/react-table/blob/fcdc3d88bc8848ca18c66c9383f1772e5e28f8d1/src/methods.js#L6-L12
Which doesn’t update the state properly with my page prop and then onFetchData will fire.
Looking into it and working on a PR for this right now.
In case someone’s facing this issue now, I had a bit of trouble with it not too long ago with making the table controlled. The problem with combining
onPageChange
andonFetchData
is that they called in a sync order. That means that when you want to manage the pages with a state, you miss the data fetching becausesetState
is asynchronous andonFetchData
will start before the page had changed. A nice workaround I did was making a proxy foronFetchData
- I wrapped it withsetTimeout
of 0 to activateonFetchData
. That way it’s set in the event-loop’s queue after the async page set, so it will be fired when the page had been set.