arco-design-mobile icon indicating copy to clipboard operation
arco-design-mobile copied to clipboard

[BUG] 无法获取最新的ref

Open canvascat opened this issue 4 months ago • 0 comments

Basic Info

  • Package Name And Version: @arco-design/[email protected]
  • Phone Model And Version: any
  • Reproduction Link: https://codesandbox.io/p/sandbox/8g86yn

打开popup后,调用方法获取ref,返回的popupRef.current不是最新的,全是null image https://github.com/arco-design/arco-design-mobile/blob/d4f1119e4754483f073c8354ae7818ee77592915/packages/arcodesign/components/popup/index.tsx#L69

建议调整写法:

    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);
            },
        }),
        [],
    );

类似的问题还有很多: https://github.com/arco-design/arco-design-mobile/blob/d4f1119e4754483f073c8354ae7818ee77592915/packages/arcodesign/components/avatar/group.tsx#L37-L39 https://github.com/arco-design/arco-design-mobile/blob/d4f1119e4754483f073c8354ae7818ee77592915/packages/arcodesign/components/avatar/index.tsx#L51-L53 .....

canvascat avatar Oct 16 '24 06:10 canvascat