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

Dynamic Component/Tag Name #123

Closed
rmdwirizki opened this issue Sep 16, 2018 · 5 comments
Closed

Dynamic Component/Tag Name #123

rmdwirizki opened this issue Sep 16, 2018 · 5 comments
Labels

Comments

@rmdwirizki
Copy link

Can we render components dynamically? To be specific, I want to render each component inside an array of tags.
I've tried this, but it didn't work (the page not showing):

import {Page1} from '../pages/Page1.imba'
import {Page2} from '../pages/Page2.imba'

const pageComponents = [ Page1, Page2 ]

export tag NavContent
  def render
    <self>
      for page in pageComponents
        # This should return <Page1 route='/page-1'>
        page:prototype.myComponent

Where myComponent defined manually in each component:

export tag Page1
  def myComponent
    return <Page1 route='/page-1'>

  def render
    <self>
      <h2> "Page 1"
@altteo
Copy link
Collaborator

altteo commented Sep 18, 2018

Not clear what you want to achieve, but here a small working example: https://scrimba.com/c/c4V23fR
And better ask such questions in the gitter channel: https://gitter.im/somebee/imba

@rmdwirizki
Copy link
Author

I see, it seems the problems are with imba-router. Because for some reason, the routing doesn't applied on the dynamic rendered page. I had forked your "small working example" in https://scrimba.com/c/cqanzTQ with no luck. I believe this is more of an imba-router issue. I'll leave this issue open for a while since I'm still figuring out a way to do this.

I think dynamic components are one of the basic pattern in front end development framework, there are a lot of use case and discussion about this topic on another framework such as react or vue. I believe by making thread on github issues will make a better chance for the community to grow and benefit from it when they across the same problem. IMHO, browsing an issue through gitter channel is not a good experience while github issue can make the problem well documented.

@altteo
Copy link
Collaborator

altteo commented Sep 28, 2018

Dynamic routing assumes that you pass the parameter to the page tag, and there depending on that parameter could render different tags.
For that you should create a tag and use somewhere with route like this:
<Page route=/page/:id>

And in the Page tag in render function:
if params:id

@aalemayhu
Copy link
Member

@rmdwirizki have you gotten a chance to play around with any of the v2 prereleases?

@stale
Copy link

stale bot commented May 4, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 4, 2021
@stale stale bot closed this as completed Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants