arco-design/arco-design-mobile

[BUG] 无法获取最新的ref

Opened this issue · 0 comments

Basic Info

打开popup后,调用方法获取ref,返回的popupRef.current不是最新的,全是null
image

useImperativeHandle(ref, () => maskingRef.current!);

建议调整写法:

    useImperativeHandle(
        ref,
        () => ({
            get dom() {
                return maskingRef.current?.dom ?? null;
            },
            get content() {
                return maskingRef.current?.content ?? null;
            },
            get mask() {
                return maskingRef.current?.mask ?? null;
            },
            setCloseScene(scene: string) {
                maskingRef.current?.setCloseScene(scene);
            },
        }),
        [],
    );

类似的问题还有很多:

useImperativeHandle(ref, () => ({
dom: domRef.current,
}));

useImperativeHandle(ref, () => ({
dom: domRef.current,
}));

.....