Skip to content

[question] Custom components in h(...) #3

Open
@heibel

Description

@heibel

First of all thanks for the greatly structured library.
I was trying to find a way to use custom components (like React.createElement):

class Item:
    def __init__(self, attrs, *args, **kwargs):
        self.attrs = attrs

    def render(self):
        check = '[x]' if self.attrs['done'] else '[ ]'
        return li([check, ' ', self.attrs['title']])


def List():
    return div(
        ul([
            h(Item, title='Todo 1', done=True),
            h(Item, title='Todo 2', done=False),
        ])
    )

Which renders:

<div>
  <ul>
    <li>[x] Todo 1</li>
    <li>[ ] Todo 2</li>
  </ul>
</div>

Seems like I need to alter the h function to do so. Am I correct?
Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions