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

State of SelectableItem not updated on new props #77

Open
romecode opened this issue Mar 6, 2020 · 3 comments
Open

State of SelectableItem not updated on new props #77

romecode opened this issue Mar 6, 2020 · 3 comments

Comments

@romecode
Copy link

romecode commented Mar 6, 2020

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 ?
#36 (comment)

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.

@AndorLundgren
Copy link

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

@lukjaki
Copy link

lukjaki commented Mar 20, 2020

This could be fixed by applying initial selected items on SelectableGroup and just passing controlled items as this prop

@heri16
Copy link

heri16 commented Jan 29, 2021

Is this a duplicate of #83 (comment)

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

No branches or pull requests

4 participants