Skip to content

Change Key of Parent Element Does Not Unmount Children #622

Closed
@rmorshea

Description

@rmorshea

Current Situation

Currently changing the key of a parent element does not cause the state of child components to get refreshed:

from idom import component, html, run, hooks
from random import random


@component
def Demo():
    h = hooks.current_hook()
    return html.div(
        html.button({"onClick": lambda event: h.schedule_render()}, "re-render"),
        HasState(),
        key=str(random()),
    )


@component
def HasState():
    state = hooks.use_state(random)[0]
    return html.p(state)


run(Demo)

Every time the button is clicked HasState should display a new random value because they key of its parent div is random, and thus its identity should always change. This does not happen though.

Only by placing the random key in HasState directly do we get the expected behavior.

Proposed Actions

Debug and fix.

Work Items

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions