【发布时间】:2019-08-10 20:25:12
【问题描述】:
您好,我正在尝试从我的计算机中选择文件并在输入字段中显示文件名,但我收到此错误
函数组件不能有引用。你的意思是使用 React.forwardRef()
https://stackblitz.com/edit/react-aogwkt?file=bulk.js
这是我的代码
import React, { Component } from "react";
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
FormControl,
IconButton,
Input,
InputAdornment,
withStyles
} from "@material-ui/core";
import Attachment from "@material-ui/icons/Attachment";
import CloudDownload from "@material-ui/icons/CloudDownload";
const BulkUpload = props => {
const { classes } = props;
return (
<div className="App">
<input
id="file_input_file"
className="none"
type="file"
ref={'abc'}
/>
<Input
id="adornment-attachment"
type="text"
fullWidth
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="Toggle password visibility"
onClick={e => {
// this.refs['abc'].click();
}}
className="login-container__passwordIcon"
>
<Attachment />
</IconButton>
</InputAdornment>
}
/>
</div>
);
};
export default BulkUpload;
我只是想在输入字段中显示选定的文件名
【问题讨论】:
-
这可能有助于在 NextJS 上使用 Native Link 组件时遇到此错误的人:stackoverflow.com/a/69767229/3556531
标签: javascript reactjs redux