Skip to content

Commit 181bb5a

Browse files
mattkrickjquense
authored andcommitted
render only children with component=null (reactjs#243)
* render only children with component=null * update jsdocs for component=null * lint
1 parent 1bc37b7 commit 181bb5a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/TransitionGroup.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const propTypes = {
99
/**
1010
* `<TransitionGroup>` renders a `<div>` by default. You can change this
1111
* behavior by providing a `component` prop.
12+
* If you use React v16+ and would like to avoid a wrapping `<div>` element
13+
* you can pass in `component={null}`. This is useful if the wrapping div
14+
* borks your css styles.
1215
*/
1316
component: PropTypes.any,
1417
/**
@@ -179,15 +182,18 @@ class TransitionGroup extends React.Component {
179182

180183
render() {
181184
const { component: Component, childFactory, ...props } = this.props;
182-
const { children } = this.state;
185+
const children = values(this.state.children).map(childFactory);
183186

184187
delete props.appear;
185188
delete props.enter;
186189
delete props.exit;
187190

191+
if (Component === null) {
192+
return children;
193+
}
188194
return (
189195
<Component {...props}>
190-
{values(children).map(childFactory)}
196+
{children}
191197
</Component>
192198
);
193199
}

yarn.lock

+9-1
Original file line numberDiff line numberDiff line change
@@ -5773,12 +5773,20 @@ promise@^7.1.1:
57735773
dependencies:
57745774
asap "~2.0.3"
57755775

5776-
prop-types@15.5.8, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0:
5776+
prop-types@15.5.8, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.8:
57775777
version "15.5.8"
57785778
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.8.tgz#6b7b2e141083be38c8595aa51fc55775c7199394"
57795779
dependencies:
57805780
fbjs "^0.8.9"
57815781

5782+
prop-types@^15.5.10, prop-types@^15.5.9, prop-types@^15.6.0:
5783+
version "15.6.0"
5784+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.0.tgz#ceaf083022fc46b4a35f69e13ef75aed0d639856"
5785+
dependencies:
5786+
fbjs "^0.8.16"
5787+
loose-envify "^1.3.1"
5788+
object-assign "^4.1.1"
5789+
57825790
proxy-addr@~2.0.2:
57835791
version "2.0.2"
57845792
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.2.tgz#6571504f47bb988ec8180253f85dd7e14952bdec"

0 commit comments

Comments
 (0)