New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onFilter function in table does not work nicely with RangePicker #12284

Closed
piuccio opened this Issue Sep 18, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@piuccio

piuccio commented Sep 18, 2018

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

3.9.2

Environment

react 16

Reproduction link

Edit on CodeSandbox

Steps to reproduce

I'm trying to use a DatePicker.RangePicker as a custom filter inside a Table and I've implemented the custom filter function as

<RangePicker
   onChange={(value) => { setSelectedKeys([value]); confirm(); }
/>

However setSelectedKeys uses setState and confirm reads the same value from state, so when setState is asynchronous, the confirm will use the previous value of selected keys, not the new value.

The solution for now is to use a setTimeout but that's not very nice, maybe a better way would be to change setSelectedKeys to accept an optional callback that can be passed to setState

  setSelectedKeys = ({ selectedKeys }: { selectedKeys: string[] }, callback) => {
    this.setState({ selectedKeys }, callback);
  }

What is expected?

I expect the dropdown filter to work all the times

What is actually happening?

Often the table doesn't filter correctly because it uses stale data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment