我有一个 Demo.tsx 文件,其中包含以下代码:
const aRef = useRef() as RefObject<HTMLDivElement>;
const bRef = useRef() as RefObject<HTMLDivElement>;
const a = 10;
const b = 10;
useEffect(() => {
if (!!aRef.current && !!bRef.current) {
const temp = functionRefCall({ARef:aref,Bref:bref,A:a,B:b})
}
}, [aRef, bRef]);
return (
<div className="aRef-container" ref={aRef} />
<div className="bRef-container" ref={bRef} />
</div>
);
下面是我的 functionRefCall.ts 文件的代码:
export interface myInterface {
Aref: HTMLElement;
Bref: HTMLElement;
A: number;
B: number;
}
export default (
i18n: i18n,
{Aref,Bref,A,B }: myInterface,
) => {
return a+b;
}
我将如何测试如果我的 ref 不为空,则调用 functionRefCall 并返回 a+b