Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs inputRef的类型-TypeScript_Reactjs_Typescript - Fatal编程技术网

Reactjs inputRef的类型-TypeScript

Reactjs inputRef的类型-TypeScript,reactjs,typescript,Reactjs,Typescript,我有一个React组件,它接受一个inputRef 我的界面 interface Props extends WithStyles<typeof styles> { body: text inputRef?: any // I am not sure which TypeScript type I should use } 界面道具随样式扩展{ 正文:正文 inputRef?:any//我不确定应该使用哪种类型的脚本 } 我的组件 const MyComponent =

我有一个React组件,它接受一个
inputRef

我的界面

interface Props extends WithStyles<typeof styles> {
  body: text
  inputRef?: any // I am not sure which TypeScript type I should use
}
界面道具随样式扩展{
正文:正文
inputRef?:any//我不确定应该使用哪种类型的脚本
}
我的组件

const MyComponent = ({
  classes,
  body,
  inputRef
}: Props) => {
  <TextField
    body={body}
    inputRef={inputRef}
  />
}
const MyComponent=({
班级,
身体,
输入输出
}:道具)=>{
}
我不确定我应该为
inputRef
使用哪种类型的TypeScript。我目前将其声明为
any
,但我需要正确的类型

我试图使用
React.createRef()
但出现错误:
命名空间“React”没有导出的成员“createRef”


我有一个as-types版本:
“@types/react:“^16.9.21”

我是这样想的。创建对元素的引用时:

const wrapperRef = useRef<HTMLDivElement>(null);
因此,您要传递的是
reObject


现在,如果您确实需要
元素ref
,请继续使用它(我不确定您尝试传递的是哪种ref)。当您查看文档或实际类型文件时,您将看到
。这是一个Typescript泛型。它允许您将类型传递给类型声明。这里有一些例子。

我想你需要
反应。ElementRef
我试过了,但是我得到了“找不到名称T”,你需要指定一个类型
T
是一个参数。例如,
React.ElementRef
const wrapperRef: RefObject<HTMLDivElement>