Skip to content

Commit 5132727

Browse files
committed
chore: Should keep trigger didUpdate with Portal render
1 parent abe50da commit 5132727

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Portal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import canUseDom from './Dom/canUseDom';
1111
export type PortalRef = {};
1212

1313
export interface PortalProps {
14-
/** @deprecated Not know who use this? */
1514
didUpdate?: (prevProps: PortalProps) => void;
1615
getContainer: () => HTMLElement;
1716
children?: React.ReactNode;
@@ -32,10 +31,12 @@ const Portal = forwardRef<PortalRef, PortalProps>((props, ref) => {
3231
initRef.current = true;
3332
}
3433

34+
// [Legacy] Used by `rc-trigger`
3535
useEffect(() => {
36-
// Not know who use this. Just keep it here
3736
didUpdate?.(props);
37+
});
3838

39+
useEffect(() => {
3940
return () => {
4041
if (containerRef.current) {
4142
containerRef.current.parentNode.removeChild(containerRef.current);

tests/Portal.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33
import PortalWrapper from '../src/PortalWrapper';
4+
import Portal from '../src/Portal';
45

56
describe('Portal', () => {
67
let container: HTMLDivElement;
@@ -27,4 +28,22 @@ describe('Portal', () => {
2728

2829
wrapper.unmount();
2930
});
31+
32+
it('didUpdate', () => {
33+
const didUpdate = jest.fn();
34+
35+
const wrapper = mount(
36+
<Portal
37+
didUpdate={didUpdate}
38+
getContainer={() => document.createElement('div')}
39+
>
40+
light
41+
</Portal>,
42+
);
43+
44+
expect(didUpdate).toHaveBeenCalledTimes(1);
45+
46+
wrapper.setProps({ justForceUpdate: true });
47+
expect(didUpdate).toHaveBeenCalledTimes(2);
48+
});
3049
});

0 commit comments

Comments
 (0)