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

selectedItems not updating based on changes from state #156

Closed
dannysun2 opened this issue Jun 12, 2019 · 3 comments · May be fixed by #157
Closed

selectedItems not updating based on changes from state #156

dannysun2 opened this issue Jun 12, 2019 · 3 comments · May be fixed by #157

Comments

@dannysun2
Copy link

Expected Behavior

Removing names (state.options) from list via onclick results in a re-render should result in an updated selectedItems list to reflect the changes from the state.

https://github.com/dannysun2/react-multi-select

Jun-12-2019 16-51-43

Actual Behavior

While the component re-renders, the selectedItems list fails to reflect the new state changes.

Steps to Reproduce the Problem

  1. Click a name to remove from list
  2. Right side (selected items list) shows "6 Selected" however, the list still shows 7 selections.
@liorheber
Copy link
Collaborator

Hi @dannysun2
Thank you for your issue.

It seems that we've never implemented the component as a controlled component, meaning that the selectedItems is basically used for initialization at this point.
I believe it would make a lot of sense to make the component work in a controlled state and I think the solution is quite simple if I'm honest.

I can't commit on a timeline at this point for a fix so I'd like to encourage you to contribute a solution to this.
I think using a lifecycle method to update the selectedItems in the state in case that the selectedItems are defined and changed should most likely solve this.

Please let me know if you're interested in issuing a PR. Otherwise, I hope we can get someone on this a little later in the future.

Thanks again!

@baptwaels
Copy link
Contributor

Controlled component feature implemented in #160

@yegor-babiy
Copy link
Contributor

As fix was pushed , I close thread

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

Successfully merging a pull request may close this issue.

4 participants