preact-compat icon indicating copy to clipboard operation
preact-compat copied to clipboard

fix: children.map when new child return null

Open ishenli opened this issue 7 years ago • 3 comments

ref: https://github.com/developit/preact-compat/issues/419

When the new child is null, should ignore , like React

ishenli avatar Feb 06 '18 12:02 ishenli

Hi,@developit can you merge this PR?

likezero avatar May 10 '18 13:05 likezero

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 avatar May 25 '18 17:05 developit

@developit children property can contain null values. I created simple example for [email protected]: https://codesandbox.io/s/wwnx5q1277?expanddevtools=1

maxsbelt avatar Aug 16 '18 13:08 maxsbelt