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

Render multiple components without a wrapping element #3415

Closed
Prinzhorn opened this issue Mar 15, 2015 · 3 comments
Closed

Render multiple components without a wrapping element #3415

Prinzhorn opened this issue Mar 15, 2015 · 3 comments

Comments

@Prinzhorn
Copy link

I haven't found a duplicate issue, only this post https://groups.google.com/forum/#!searchin/reactjs/render$20multiple/reactjs/pHNJe8trFOg/J-zd4jxAkJ4J

I have a valid use case and like to share it.

I'm building a framework for storytelling based on react. Every single element is positioned fixed as I've written a custom layout engine and need full control over everything. My entry level structure looks something like this

<Story>
    <Grid />
    <UI />
</Story>

<Grid> renders all the actual items (<GridItem>) of the story (text, images, videos, etc.). <UI /> renders UI elements that are common to every story. For example a <VolumeControl> for controling the volume of audio/video items.

If I'd render the structure as given above, this would be the result

<div>
    <div>
        <!--list of GridItems-->
    </div>
    <div>
        <!--list of UI components-->
    </div>
</div>

Since everything is positioned fixed, this does not work. The UI layer covers everything, making it unusable (e.g. can't click on videos). That's why I'm currently forced to do the following in the render method of Story

<div>
    <Grid />
    <VolumeControl />
    <Navigation />
    <ShareButtons />
</div>

This works but is ugly as I lose separation. I don't want the Story component to have to know about every UI component. Sth. like a virtual <Fragment> component that renders it's children without a wrapper element would solve the problem as I could return it from the <UI> component.

I know this is a rare use-case, I'm rather talented at reaching the edge cases of every framework I touch.

Funny how writing down these things sometimes magically makes your brain do useful stuff. I found another workaround. I'm using visiblity:none on the UI layer and visibility:visible on the UI components. But it's a hack, nothing more.

@gaearon
Copy link
Collaborator

gaearon commented Mar 15, 2015

I believe this to be a duplicate of #2127.

@Prinzhorn
Copy link
Author

I believe this to be a duplicate of #2127.

Absolutely. I knew there had to be one but I couldn't find it (found it some weeks ago). Closing this and I'll explicitly link link it from the other issue as well to point to my use-case.

@IUnknown68
Copy link

IUnknown68 commented Jan 26, 2017

@Prinzhorn Just stumbled across this, and even that you probably don't need any workaround anymore, I believe I know another one: Setting the height of the enclosing divs to 0 and adding overflow:visible to them should still show the content, but not the enclosing div anymore.
Edit: It's probably enough to do this for the UI-div.

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

3 participants