我正在嘗試使用 React 構(gòu)建一個(gè) csv 文件上傳器。I am getting the "Invalid attempt to spread non-iterable instances" error when the file is selected and I try to set the state with it. 這是我給出該錯(cuò)誤的代碼:const IFImport = (props) => { const [file, setFile] = useState(null); const [loading, setLoading] = useState(false); const onUpload = async (e) => { const csvFile = e; console.log(csvFile) setFile(...file, csvFile) } return ( <> <ContentRow> <h1> <Link to={"/"}> <Button color="link"><</Button> </Link> Upload Enrollment Information <ErrorList error={props.error} /> </h1> </ContentRow> <ContentRow> <Label>Upload a CSV File for Enrollment</Label> <FormGroup> <div> {file !== null ? <p>{file.name}</p> : ""} </div> <div> <Input type="file" name="data.file" multiple={false} onChange={e => onUpload(e)} accept="/csv" />{" "} </div> </FormGroup> </ContentRow> </> );};export default IFImport;我認(rèn)為這是在此 onUpload 函數(shù)中設(shè)置狀態(tài)的問(wèn)題,所以我嘗試不在此處設(shè)置狀態(tài),但后來(lái)我只是得到一個(gè)合成偶數(shù)錯(cuò)誤。誰(shuí)能告訴我處理這種上傳的最佳方法?
類型錯(cuò)誤:傳播不可迭代實(shí)例和綜合事件的無(wú)效嘗試
茅侃侃
2023-04-01 15:05:36