Hello,
Why I can not export this component:
import React, { useState } from "react";
import axios from "axios";
//import React, { Component } from 'react
//import React, { Component } from 'react';
export const FileUpload = () => {
const [file, setFile] = useState();
const [fileName, setFileName] = useState();
const SaveFile = (e) => {
console.log(e.target.files[0]);
setFile(e.target.files[0]);
setFileName(e.target.files[0].name);
};
const UploadFile = async (e) => {
cons.log(file);
formData = new FormData();
formData.append("formFile", file);
formData.append("fileName", fileName);
try {
const res = await axios.post("https://localhost:44323/api/file", FormData);
cons.log(res);
} catch (ex) {
console.log(ex);
}
};
return (
<>
<input type="file" onChange={SaveFile} />
<input type="button" value="upload" onClick={UploadFile} />
</>
);
};
When run the code, get this error:
./src/components/FileUpload.js Line 22:9: 'cons' is not defined no-undef Line 23:9: 'formData' is not defined no-undef Line 24:9: 'formData' is not defined no-undef Line 25:9: 'formData' is not defined no-undef Line 29:13: 'cons' is not defined no-undef
Where is wrong?
thanks,
Saeed