feat: Fragment support to have multiple children in a component#32
Merged
maartenbreddels merged 2 commits intomasterfrom Mar 22, 2024
Merged
feat: Fragment support to have multiple children in a component#32maartenbreddels merged 2 commits intomasterfrom
maartenbreddels merged 2 commits intomasterfrom
Conversation
Similar to React, where children in a Fragment will be 'extended' to
a parent list (like children) instead of 'appended'
Example
```python
import reacton
import reacton.ipywidgets as w
@reacton.component
def Children():
with reacton.Fragment(): # option for reacton, mandatory for solara
w.Button(description="1")
w.Button(description="2")
@reacton.component
def Test():
with w.VBox():
Children()
Test()
```
Since solara overrides the '_default_container', this is mandatory to
use with solara (even when just imported). For solara v2 we will
probably also start using fragments.
6cf884c to
78f959e
Compare
78f959e to
19d3ce3
Compare
Contributor
Author
|
To make this work in solara, use: import solara # this changes reacton.core. _default_container
import reacton.core
# now restore it
reacton.core. _default_container = reacton.Fragment |
Contributor
Author
|
Note, Fragment does not have to be used explicitly. import reacton
import reacton.ipywidgets as w
@reacton.component
def Children():
# will use fragment implicitly, because we have 2 elements
w.Button(description="1")
w.Button(description="2")
@reacton.component
def Test():
with w.VBox():
Children()
Test() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Similar to React, where children in a Fragment will be 'extended' to a parent list (like children) instead of 'appended'
Example
Since solara overrides the '_default_container', this is mandatory to use with solara (even when just imported). For solara v2 we will probably also start using fragments.