question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onFetchData fires at the wrong time

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
lightninglu10commented, Jul 27, 2018

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.

1reaction
Motistudiocommented, Nov 26, 2019

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 and onFetchData 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 because setState is asynchronous and onFetchData will start before the page had changed. A nice workaround I did was making a proxy for onFetchData - I wrapped it with setTimeout of 0 to activate onFetchData. 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found