diff --git a/src/index.js b/src/index.js index ba0fe64..fe8c728 100644 --- a/src/index.js +++ b/src/index.js @@ -185,12 +185,26 @@ function unmountComponentAtNode(container) { const ARR = []; // This API is completely unnecessary for Preact, so it's basically passthrough. + let Children = { map(children, fn, ctx) { if (children == null) return null; children = Children.toArray(children); if (ctx && ctx!==children) fn = fn.bind(ctx); - return children.map(fn); + const newChildren = []; + + children.forEach((old, index) => { + if (old === void 0 || old === false || old === true) { + old = null; + } + const newChild = fn(old, index); + if (newChild == null) { // when the return value is null, ignore + return; + } + newChildren.push(newChild); + }); + + return newChildren; }, forEach(children, fn, ctx) { if (children == null) return null; @@ -592,7 +606,7 @@ PureComponent.prototype.shouldComponentUpdate = function(props, state) { }; function unstable_batchedUpdates(callback) { - callback(); + callback(); } export { diff --git a/test/component.js b/test/component.js index 33faeda..f1869f3 100644 --- a/test/component.js +++ b/test/component.js @@ -543,4 +543,36 @@ describe('components', () => { expect(spy).not.to.have.been.called; }); }); + + describe('ReactChildren', () => { + it("should ignore when child return null", () => { + let zero =
; + let one = null; + let two = ; + let three = null; + let four = ; + + let mapped = [ + , // Key should be joined to obj key + null, // Key should be added even if we don't supply it! + , // Key should be added even if not supplied! + , // Map from null to something. + + ]; + let instance = ( +