Do you want to request a feature or report a bug?
I think this is a bug.
What is the current behavior?
If you try to use React.Children.count, and the children contains a child with the value false, the result will be off by one. For example,
function Root() {
return (
<Hello>
{false}
</Hello>
);
}
function Hello({children}) {
return (
<div>
Count: {React.Children.count(children)}
<br />
toArray length: {React.Children.toArray(children).length}
</div>
);
}
Will render
Count: 1
toArray length: 0
If you replace false with null or [] the count will be 0.
Here's a fiddle that demonstrates the issue.
What is the expected behavior?
The count shouldn't include false nodes.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I've repro'd this on Firefox 48 and Chrome 53. I don't know if this worked in previous versions of React.
Do you want to request a feature or report a bug?
I think this is a bug.
What is the current behavior?
If you try to use
React.Children.count, and the children contains a child with the valuefalse, the result will be off by one. For example,Will render
If you replace
falsewithnullor[]the count will be 0.Here's a fiddle that demonstrates the issue.
What is the expected behavior?
The count shouldn't include
falsenodes.Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
I've repro'd this on Firefox 48 and Chrome 53. I don't know if this worked in previous versions of React.