Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
heibel opened this issue May 16, 2019 · 0 comments
Open

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

heibel opened this issue May 16, 2019 · 0 comments

Comments

@heibel
Copy link

heibel commented May 16, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant