Skip to content

All child states wiped upon any child key change #652

Closed

Description

@Archmonger

Current Situation

If two children obtain their key from a parent, both children's use_state are wiped if either child changes key.

from idom import component, html, run, hooks


@component
def Parent():
    state, set_state = hooks.use_state(1)
    return html.div(
        html.button({"onClick": lambda event: set_state(state + 1)}, "click me"),
        Child("key-0"),
        Child(f"key-{state}"),
    )


@component
def Child(child_key):
    state, set_state = hooks.use_state(0)

    @hooks.use_effect
    async def whatever():
        if state:
            return
        print(f"Child {child_key!r} has no state")
        set_state(1)

    return html.div(
        child_key,
        key=child_key,
    )


run(Parent)

Proposed Actions

Investigate and resolve this parent-child key abnormality

Work Items

See above

Activity

  1. changed the title [-]All child states wiped upon any child mutation[/-] [+]All child states wiped upon any child key change[/+] on Feb 7, 2022
  2. added this to the 1.0 milestone on Feb 7, 2022
  3. rmorshea commented on Feb 9, 2022

    @rmorshea
    Collaborator

    I think this is related to #663

  4. added a commit that references this issue on Feb 16, 2022
    a9cfadf
  5. added a commit that references this issue on Feb 18, 2022
    99219f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions