diff --git a/components/space/__tests__/__snapshots__/demo.test.js.snap b/components/space/__tests__/__snapshots__/demo.test.js.snap index a733610238..43e2edaa52 100644 --- a/components/space/__tests__/__snapshots__/demo.test.js.snap +++ b/components/space/__tests__/__snapshots__/demo.test.js.snap @@ -395,6 +395,12 @@ exports[`renders ./components/space/demo/debug.md correctly 1`] = ` +
+
{ expect(wrapper.find('.ant-space-item').length).toBe(3); }); + + it('should be keep store', () => { + function Demo() { + const [state, setState] = React.useState(1); + + return ( +
{ + setState(value => value + 1); + }} + > + {state} +
+ ); + } + function SpaceDemo() { + const [visible, setVisible] = useState(true); + function onChange() { + setVisible(!visible); + } + return ( + + {visible &&
space
} + +

Three

+
+ ); + } + const wrapper = mount(); + + expect(wrapper.find('#demo').text()).toBe('1'); + + act(() => { + wrapper.find('#demo').simulate('click'); + }); + + expect(wrapper.find('#demo').text()).toBe('2'); + + act(() => { + wrapper.find('p').simulate('click'); + }); + + expect(wrapper.find('#demo').text()).toBe('2'); + }); }); diff --git a/components/space/index.tsx b/components/space/index.tsx index ff5da230a1..3d26bfcdfa 100644 --- a/components/space/index.tsx +++ b/components/space/index.tsx @@ -1,6 +1,5 @@ import * as React from 'react'; import classNames from 'classnames'; -import toArray from 'rc-util/lib/Children/toArray'; import { ConfigConsumerProps, ConfigContext } from '../config-provider'; import { SizeType } from '../config-provider/SizeContext'; @@ -35,8 +34,7 @@ const Space: React.FC = props => { ...otherProps } = props; - const items = toArray(children); - const len = items.length; + const len = React.Children.count(children); if (len === 0) { return null; @@ -60,13 +58,13 @@ const Space: React.FC = props => { return (
- {items.map((child, i) => ( + {React.Children.map(children, (child, i) => (