Allow for <component> to be a conditional wrapper ie. only render children.
See original GitHub issueWhat 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:
- Created 2 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:I was suprised to find out this is not supported by Vue. We need this! 😄