-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Closed
Description
Use case:
A set of elements should be wrapped in a <div> (with a class), but only depending on certain scenarios.
Example:
Test Component
import * as React from 'react';
class Test extends React.Component {
render() {
const Wrapper = this.props.wrap ? 'div' : React.Fragment;
return (
<Wrapper className={'wrapper'}>
<div>Child 1</div>
<div>Child 2</div>
</Wrapper>
);
}
}
export default Test;Scenario 1
<Test /><div>Child 1</div>
<div>Child 2</div>Scenario 2
<Test wrap={true} /><div class="wrapper">
<div>Child 1</div>
<div>Child 2</div>
</div>Even though the above examples will actually output the way they are intended, an error is still being thrown:
Solution:
Allow the className prop on Fragments, but simply ignore it, don't do anything with it.
Of course there are many other way this can be achieved without using Fragments, but I think this approach is really clean.
Metadata
Metadata
Assignees
Labels
No labels
