react-selectable-fast
react-selectable-fast copied to clipboard
State of SelectableItem not updated on new props
Hey!
Not sure if this is a proper way to use this.
{this.props.items.map((item, i) => { let selected = this.props.selected.indexOf(item) > -1; return (<SelectableComponent key={i} data={item} isSelected={selected} />); })}
This is tied into a parent which passes props to determine already selected items which works. When I setState in the parent and propagate new props it seems that once mounted with initial props, subsequent updates/renders propagate props as expected but don't update state on SelectableComponent i.e.
props data {architecture: "i386", bootupTimeStamp: 1582050413.…} isSelected false new prop : "" state isSelected true isSelecting false context value {selectable: {…}} rendered by List Devices Parent
Snippet from React inspector.
Anyway to "deselect" via props ? https://github.com/valerybugakov/react-selectable-fast/issues/36#issuecomment-481742148
I guess something like this would work https://til.hashrocket.com/posts/p8tr2ah430-forcing-a-child-remount-with-the-key-prop Setting a key on <List> definitely works.
Hi. I also need a controlled component.
I assumed that you could set the prop isSelected on those that you would like to have selected. Is there a way of select|deselect after initial render?
I usually prefix my props with default on the uncontrolled ones:
- defaultIsSelected <-- used when you want a uncontrolled component
- Selected <-- used when you want to have a controlled
This could be fixed by applying initial selected items on SelectableGroup and just passing controlled items as this prop
Is this a duplicate of https://github.com/valerybugakov/react-selectable-fast/issues/83#issuecomment-755340674