question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow for <component> to be a conditional wrapper ie. only render children.

See original GitHub issue

What problem does this feature solve?

This use case is often called a conditional wrapper . There sometimes is a need to wrap an element in a link or other elements for styling. But instead of making multiple similar components or providing a placeholder tag like div . It would be great to be able to simply leave out the wrapping. This is important since sometimes a even simple ‘div’ wrapper can break styling as well/ would need extra consideration/ work/ moving parts.

What does the proposed API look like?

I think the most clean and practical way for programmatic use would be to use the is prop. Either by passing in a falsy value, or by passing in ‘template’, a tag that doesn’t render in the html.

Template Output
<component :is="false"><span>Child</span></component> <span>Child</span>
OR
<component :is="'template'"><span>Child</span></component> <span>Child</span>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
andrewsm80commented, Jun 27, 2022

If something like this does eventually get implemented, I think it would make a lot more sense to use a directive, analogous to the v-if directive:

  <div v-wrap-if="someCondition">
    <span>
      This is a span that is sometimes wrapped up in a div.
    </span>
  </div>
3reactions
Harraldcommented, Jun 3, 2022

I was suprised to find out this is not supported by Vue. We need this! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to conditionally wrap an element in React - Hackages Blog
To render a different wrapping element based on a condition, we can use this one line functional component and determine in our component...
Read more >
How do I conditionally wrap a React component?
If it exists, I need to render the component wrapped in an <a href={this.props.url}> . Otherwise it just gets rendered as a <div/>...
Read more >
7 Ways of Achieving Conditional Rendering in React
We're conditionally rendering our errorMessage component only if the errorCondition variable has a truthy value, otherwise JS will stop ...
Read more >
React Children And Iteration Methods - Smashing Magazine
But in some cases, we want to inspect the children prop to maybe wrap each child in another element/component or to reorder or...
Read more >
How to conditionally wrap JSX with a component in React
In this post, we create a Wrapper that either renders its children in a component or it doesn't. An example scenario. Let's say...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found