raynor85 / react-native-material-selectize

A React Native component inspired to Selectize which follows Material Design guidelines.
MIT License
55 stars 32 forks source link

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

Open Diwei-Chen opened 5 years ago

BukhariMuslim commented 5 years ago

Yes you can, check this #14

Diwei-Chen commented 5 years ago

@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.

BukhariMuslim commented 5 years ago

This feature is currently rollback, regardless to this comment.

Diwei-Chen commented 5 years ago

Great, thanks @BukhariMuslim , FYI @adamgins

ReSqAr commented 5 years ago

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});