Skip to content

Commit 101c1dc

Browse files
authored
fix: React 17 order miss (#306)
1 parent afc5670 commit 101c1dc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/useNotification.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import type { CSSMotionProps } from 'rc-motion';
12
import * as React from 'react';
3+
import type { NotificationsRef, OpenConfig, Placement } from './Notifications';
24
import Notifications from './Notifications';
3-
import type { Placement } from './Notifications';
4-
import type { NotificationsRef, OpenConfig } from './Notifications';
5-
import type { CSSMotionProps } from 'rc-motion';
65

76
const defaultGetContainer = () => document.body;
87

@@ -146,7 +145,12 @@ export default function useNotification(
146145
}
147146
});
148147

149-
setTaskQueue([]);
148+
// React 17 will mix order of effect & setState in async
149+
// - open: setState[0]
150+
// - effect[0]
151+
// - open: setState[1]
152+
// - effect setState([]) * here will clean up [0, 1] in React 17
153+
setTaskQueue((oriQueue) => oriQueue.filter((task) => !taskQueue.includes(task)));
150154
}
151155
}, [taskQueue]);
152156

0 commit comments

Comments
 (0)