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

Docs request — Can render a component assigned to a variable? #91

Closed
nichoth opened this issue Sep 19, 2022 · 1 comment
Closed

Docs request — Can render a component assigned to a variable? #91

nichoth opened this issue Sep 19, 2022 · 1 comment
Labels
QUESTION Further information is requested

Comments

@nichoth
Copy link
Contributor

nichoth commented Sep 19, 2022

question / docs request

The scenario: I'm making a single page app, and I get a child component client side, from a 'router' module.

class MyApp extends Tonic {
  render () {
    const child = router.match('/example')
    return this.html`<div>
      // how to render `child` here?
      <${child></${child}>
    </div>`
  }
}

How to make this work? Normally in this scenario you would just return html with the child component's class/tag name?

render () {
  return this.html`<my-child>example</my-child>`
}
@nichoth nichoth added the QUESTION Further information is requested label Sep 19, 2022
@nichoth
Copy link
Contributor Author

nichoth commented Sep 20, 2022

You would want to either return a string (the tag name) from the route function, or this is how we convert between camel-case class names and tag names in tonic:

function getTagName (camelName) {
    return camelName.match(/[A-Z][a-z0-9]*/g).join('-').toLowerCase()
}

You can use that like this, given a tonic class myComponent:

return this.html`
  <${getTagName(myComponent.name)}>hello</${getTagName(myComponent.name)}>
`

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

No branches or pull requests

1 participant