Skip to content
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

Double request in the Patients List #97

Open
BogdanScherban opened this issue Jul 11, 2019 · 4 comments
Open

Double request in the Patients List #97

BogdanScherban opened this issue Jul 11, 2019 · 4 comments

Comments

@BogdanScherban
Copy link
Collaborator

@fzaninotto

Francois, could you please help me with this issue. I can't found a reason of double request in List-component:
https://drive.google.com/file/d/1qJkFUqUYNyjARSjCrUp2Mxgcrq2sQbZQ/view

You can see two problems:

  1. In first case it run double request with "tweed";
  2. In the second request in run double request with for previous search (tweed) and new search (smith)

How it works:

  1. Patients List is empty by default;
  2. User input patient lastname to the search field. This value saves in Store:
    Screenshot from 2019-07-11 12-22-14
    Screenshot from 2019-07-11 12-23-08
  3. List re-render by this condition:

    It increase key = key+1, and patients table refreshed.

Similar, it run request with previous value, and after this - run request with new value.

I don't understand how to prevent the first request.

@fzaninotto
Copy link
Collaborator

When you update the state based on the current state, you should use the function variant of setState (which you do) and use the state from the function parameters rather than from this (which you don't do):

    filterByUserSearch = () => {
        this.setState((state, props) => {
            if (state.filterText !== props.userSearch) {
                return {
                    filterText: props.userSearch,
-                   key: this.state.key + 1,
+                   key: state.key + 1,
                }
            }
        });
    };

I don't know if that's the cause of the problem but it might certainly cause bugs.

@fzaninotto
Copy link
Collaborator

You're changing the state in componentWillReceiveProps. That's an edge case that the React doc advises against (see https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops).

I ythink you should use componentDidUpdate instead.

@BogdanScherban
Copy link
Collaborator Author

@tony-shannon @fzaninotto

Thanks, Francois! The issue has been done!

@kuvakina
Copy link
Collaborator

@tony-shannon @PhilBarrett The issue with requests from the previous search in the new search was solved. Please see the video:
https://drive.google.com/file/d/1DdFPxhBYkGIWSlBWC4byDWyhbxXmHF09/view

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

No branches or pull requests

4 participants