Reactjs 如何使用typescript将多个ref传递给forwardRef

Reactjs 如何使用typescript将多个ref传递给forwardRef,reactjs,typescript,Reactjs,Typescript,这是我的代码,目前有效。 它检测组件表的宽度,然后在包装器上设置该宽度 包装纸 从“React”导入React; 类型shapeWrapper={ 过滤:字符串[] }; 类型shapeState={ tableWidth:string, 可见性:字符串 }; 类包装器扩展组件{ private refParent=React.createRef(); public ref=React.createRef(); //将上述内容替换为 /* public refTable=React.create

这是我的代码,目前有效。 它检测组件表的宽度,然后在包装器上设置该宽度

包装纸
从“React”导入React;
类型shapeWrapper={
过滤:字符串[]
};
类型shapeState={
tableWidth:string,
可见性:字符串
};
类包装器扩展组件{
private refParent=React.createRef();
public ref=React.createRef();
//将上述内容替换为
/*
public refTable=React.createRef(),
public refTds:HTMLTableElement[]=filtered.map(item=>React.createRef());
公共参考={
参考表,
参考文献
}
*/
构造函数(道具:shapeWrapper){
超级(道具);
this.setWrapperWidth=this.setWrapperWidth.bind(this);
此.state={
tableWidth:'0',
可见性:“隐藏”
};
}
setWrapperWidth(tableWidth:string){
这是我的国家({
桌宽,
可见性:“可见”
});
}
render(){
const{filtered}=this.props;
const{tableWidth}=this.state;
const{setWrapperWidth}=这个;
常量{ref,refParent}=这个;
返回(
{setWrapperWidth(tableWidth);}
/>
);
}
};
导出默认包装器;
桌子
import React,{forwardRef,useffect}来自“React”;
导出类型形状表={
已筛选:字符串[][],
onMount:(tableWidth:string)=>void
};
类型Ref=HTMLTableElement;
const Table=forwardRef({filtered,onMount},ref)=>{
useffect(()=>{
if(ref&&typeof ref!=“函数”&&ref.current){
const tableWidth:string=window.getComputedStyle(ref.current.getPropertyValue(“宽度”);
onMount(表宽);
}
},[ref]);
返回过滤长度
? (
{filtered.map((项,ind)=>(
{item}
))}
)
:null
});
导出默认表;
我现在要做的是检测td列的宽度。 我需要提供多个参考,但我所有的尝试似乎都失败了。Typescript希望过去的引用始终是目标,而不是数组。我如何在另一端的forwardRef上传递和接收它: 这是我想要做的一个例子,但是typescript并不期望'ref'是一个对象,更不用说数组了

public refTable = React.createRef<HTMLTableElement>(),
public refTds:HTMLTableElement[] = filtered.map(item => React.createRef<HTMLTableElement>());
public ref = {
  refTable,
  refTds
}

public refTable=React.createRef(),
public refTds:HTMLTableElement[]=filtered.map(item=>React.createRef());
公共参考={
参考表,
参考文献
}