react-selectable-fast icon indicating copy to clipboard operation
react-selectable-fast copied to clipboard

Reassigning isSelected prop does not update internal isSelected state

Open blozano824 opened this issue 5 years ago • 3 comments

blozano824 avatar May 01 '20 02:05 blozano824

https://github.com/valerybugakov/react-selectable-fast/blob/ef6ff11beb12a37bc56591e9ad5239767c59e94f/src/CreateSelectable.tsx#L20 this will only set once - when the component is first instantiated. if props is updated later this won't update. maybe that is by design but would think that props should override (say from a server update).

timofei7 avatar May 01 '20 20:05 timofei7

I hope SelectableItem created by createSelectable can have a deselect/select prop function in order that we can modify manually isSelected prop inside SelectableItem

dnquang1996vn avatar May 29 '20 04:05 dnquang1996vn

As a workaround I've used componentWillReceiveProps event to update SelectableItem state. With this fix items selects when application state changes.

const SelectableItem = createSelectable(AccountItem)
SelectableItem.prototype.componentWillReceiveProps = function (props) {
  if (props.isSelected != this.state.isSelected)
    this.setState({ ... this.state, isSelected: props.isSelected })
};

Ruslan avatar Jan 06 '21 14:01 Ruslan