-
I'm confused about what's happening here. Consider this App: fromreactpyimportcomponent, use_statefromreactpy.htmlimportdiv, buttonfromreactpy.core.typesimportState@componentdefItem(item: str, items: State): color=use_state(None) defdeleteme(event): items.set_value(lambdaitems: [iforiinitemsif (i!=item)]) defcolorize(event): color.set_value(lambdac: "blue"ifnotcelseNone) returndiv({'style':{'background-color': color.valueor"transparent", 'padding': "5px"}}, div( button({'onClick': colorize}, f"Color {item}"), button({'onClick': deleteme}, f"Delete {item}"), ), ) @componentdefApp(): items=use_state(["A", "B", "C"]) returndiv( [ Item(item, items, key=item) foriteminitems.value ] )I embed it from a Django template. Here's the equivalent ReactJS implementation for reference. Now, when I delete Item A then click to color Item B, then unexpectedly, Item C appears overwritten. reactpy==1.0.1 |
BetaWas this translation helpful?Give feedback.
Replies: 1 comment 7 replies
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This might be related to a common issue in Python, since all variables are passed by reference. See this page for more details. You will need to create a wrapper function for your event and pass in |
BetaWas this translation helpful?Give feedback.
Fix is released in https://github.com/reactive-python/reactpy/releases/tag/reactpy-v1.0.2