How to properly use children in Reacton component #18
-
Hello! What is the proper way to add children to nested components? I tried to use import reacton
import reacton.ipywidgets as w
@reacton.component
def Wrapper(children):
with w.HBox() as wrapper:
w.HTML(value="A")
wrapper.add_children(children)
w.HTML(value="C")
return wrapper
@reacton.component
def Example():
with Wrapper() as wrapper:
w.HTML(value="B")
return wrapper
# This example prints "B A C" while I expected "A B C" Is there a way to insert children to some place inside context manager? UPD: I've got an expected result by manually adding each child to the latest container_adder: def Children(children):
rc = get_render_context()
if rc.container_adders:
for child in children:
rc.container_adders[-1].add(child)
@reacton.component
def Wrapper(children):
with w.HBox() as wrapper:
w.HTML(value="A")
Children(children)
w.HTML(value="C")
return wrapper Is there a more convenient way to do this? |
Beta Was this translation helpful? Give feedback.
Answered by
maartenbreddels
Sep 7, 2023
Replies: 1 comment 1 reply
-
Hi Egor, nice to see you dove into the code :) using display also works in reacton and solara: import reacton
import reacton.ipywidgets as w
@reacton.component
def Wrapper(children):
with w.HBox() as wrapper:
w.HTML(value="A")
display(*children)
w.HTML(value="C")
return wrapper
@reacton.component
def Example():
with Wrapper() as wrapper:
w.HTML(value="B")
w.HTML(value="B+")
return wrapper Is this what you needed? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
egormkn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Egor,
nice to see you dove into the code :)
using display also works in reacton and solara:
Is this what you needed?