Skip to content

Commit

Permalink
fix(message): prevent dom not match between SSR and CSR
Browse files Browse the repository at this point in the history
  • Loading branch information
jigsawye committed Apr 8, 2021
1 parent bb701aa commit 850895b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/message/HooksMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ interface HooksMessageProps {
}

const HooksMessage: FC<HooksMessageProps> = ({ setTrigger }) => {
const [mounted, setMounted] = useState(false);
const refMap = useRef(new WeakMap());
const cancelMap = useRef(new WeakMap());
const [messages, setMessages] = useState<Message[]>([]);
const getUid = useUID();

useEffect(() => {
setMounted(true);
}, []);

const trigger = useCallback(
({ content, duration }: MessageOptions, type: StatusType) => {
return new Promise<boolean>((resolve) => {
Expand Down Expand Up @@ -137,6 +142,10 @@ const HooksMessage: FC<HooksMessageProps> = ({ setTrigger }) => {
config,
});

if (!mounted) {
return null;
}

return (
<Portal defaultOrder={StackingOrder.MESSAGE}>
<MessageContainer>
Expand Down

0 comments on commit 850895b

Please sign in to comment.