react-native-material-selectize icon indicating copy to clipboard operation
react-native-material-selectize copied to clipboard

Can selectedItems be repopulated by state variables after the component is mounted?

Open Diwei-Chen opened this issue 7 years ago • 5 comments

Diwei-Chen avatar Nov 27 '18 08:11 Diwei-Chen

Yes you can, check this #14

BukhariMuslim avatar Nov 29 '18 05:11 BukhariMuslim

@BukhariMuslim Sorry, can the prop selectedItems be repopulated?

Can it be changed by state variable after it has been initialised?

Let's say my items list is [A, B, C, D], selectedItems firstly passed in is [A, B] which points to state variable initSelectedList [A, B]. There are two chips rendering on screen.

If I change initSelectedList to [A, B, C] by a button click, it doesn't seem like C is added to the chips.

Diwei-Chen avatar Nov 29 '18 05:11 Diwei-Chen

This feature is currently rollback, regardless to this comment.

BukhariMuslim avatar Dec 05 '18 05:12 BukhariMuslim

Great, thanks @BukhariMuslim , FYI @adamgins

Diwei-Chen avatar Dec 05 '18 06:12 Diwei-Chen

Hi, thanks for this nice component!

I also had the problem mentioned above, my workaround for the moment is the following:

  1. Add this._child_selectize = null; to the constructor in the surrounding component.
  2. Add ref={c => this._child_selectize = c} to the Selectize component
  3. Let items and selectedItems be the variables with the new content, then this code updates the Selectize component:
const selectize = this._child_selectize, itemId = selectize.props.itemId;
items = selectize._getNormalized({itemId}, items);
selectedItems = selectize._getNormalized({itemId}, selectedItems);
selectize.setState({items, selectedItems});

ReSqAr avatar Feb 06 '19 05:02 ReSqAr