preact-compat
preact-compat copied to clipboard
fix: children.map when new child return null
ref: https://github.com/developit/preact-compat/issues/419
When the new child is null, should ignore , like React
Hi,@developit can you merge this PR?
I'm still confused how it's possible to end up with props.children
containing values like null
or undefined
. Preact strips those out - see this demo:
https://jsfiddle.net/developit/z97ua3m3/
So it would seem that, regardless of whether this PR is merged or not, Preact will still have removed the empty values prior to map()
running, right?
Setting that aside, I think this could be simplified a bit? Something like:
map(children, fn, ctx) {
if (children == null) return null;
children = Children.toArray(children);
if (ctx) fn = fn.bind(ctx);
return children.filter(Boolean).map(fn).filter(Boolean);
}
@developit children property can contain null
values. I created simple example for [email protected]
: https://codesandbox.io/s/wwnx5q1277?expanddevtools=1