I have been trying to upload a file to an api but getting this error Objects are not valid as a React child, use an array instead

I have been trying to submit a file to my api but I am getting this Objects are not valid as a React child . If you meant to render a collection of children, use an array instead. Below is my code for submitting the data

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
const handleSubmit = async () => {
try {
const resumeData = selectedResume?.id ? { resumeId: selectedResume.id } : { resumeFile: selectedResume };
const values = questions?.map((question) => ({
id: question?.id,
answer: answers[`question${question?.id}`],
}));
const data = {
jobId: job?.id,
resumeType: 'internal',
...resumeData,
values,
};
console.log('data sent to api', data);
const response = await axios.post(`/api/v1/jobs/stu/apply/`, data);
console.log(response.data);
enqueueSnackbar(response.data.message);
onClose();
window.location.reload();
} catch (error) {
console.log(error);
}
};
</code>
<code> const handleSubmit = async () => { try { const resumeData = selectedResume?.id ? { resumeId: selectedResume.id } : { resumeFile: selectedResume }; const values = questions?.map((question) => ({ id: question?.id, answer: answers[`question${question?.id}`], })); const data = { jobId: job?.id, resumeType: 'internal', ...resumeData, values, }; console.log('data sent to api', data); const response = await axios.post(`/api/v1/jobs/stu/apply/`, data); console.log(response.data); enqueueSnackbar(response.data.message); onClose(); window.location.reload(); } catch (error) { console.log(error); } }; </code>
   

    const handleSubmit = async () => {
        try {
          const resumeData = selectedResume?.id ? { resumeId: selectedResume.id } : { resumeFile: selectedResume };
    
          const values = questions?.map((question) => ({
            id: question?.id,
            answer: answers[`question${question?.id}`],
          }));
    
          const data = {
            jobId: job?.id,
            resumeType: 'internal',
            ...resumeData,
            values,
          };
          console.log('data sent to api', data);
          const response = await axios.post(`/api/v1/jobs/stu/apply/`, data);
          console.log(response.data);
          enqueueSnackbar(response.data.message);
          onClose();
          window.location.reload();
        } catch (error) {
          console.log(error);
        }
      }; 

and below is the code from where I am submitting this resume

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const ResumeStep = ({ onNext, onCancel }) => {
const [resumeList, setResumeList] = useState([]);
const [selectedResume, setSelectedResume] = useState('');
const [selectedFile, setSelectedFile] = useState(null);
useEffect(() => {
fetchResume();
}, []);
const fetchResume = async () => {
try {
const res = await axios.get('/api/v1/jobs/stu/resumes/');
setResumeList(res.data);
} catch (error) {
console.error('Error fetching resumes:', error);
}
};
const handleResumeChange = (event) => {
setSelectedResume(event.target.value);
};
const handleFileChange = (event) => {
setSelectedFile(event.target.files[0]);
};
const handleRemove = () => {
setSelectedFile(null);
};
const handleSubmit = () => {
if (selectedFile) {
onNext(selectedFile);
} else {
onNext(selectedResume);
}
};
return (
<>
<DialogTitle>Submit Resume</DialogTitle>
<FormControl fullWidth sx={{ padding: '20px' }}>
<FormControl fullWidth sx={{ marginBottom: '20px' }}>
<InputLabel>Select a resume</InputLabel>
<Select value={selectedResume} onChange={handleResumeChange} label="Select a resume">
{resumeList.map((resume) => (
<MenuItem key={resume.id} value={resume}>
{resume.name}
</MenuItem>
))}
</Select>
</FormControl>
<Divider sx={{ marginBottom: '10px' }} />
<FormControl fullWidth sx={{ padding: '20px' }}>
<InputLabel>Upload a resume file</InputLabel>
<Input
type="file"
onChange={handleFileChange}
inputProps={{ accept: '.pdf,.doc,.docx' }}
/>
{selectedFile && selectedFile.name && (
<Typography variant="body1" sx={{ mt: 1, fontWeight: 'bold', color: 'text.primary' }}>
{selectedFile.name}
</Typography>
)}
</FormControl>
</FormControl>
<DialogActions>
<Button onClick={onCancel} color="grey" variant="contained">
Cancel
</Button>
<Button onClick={handleSubmit} color="primary" variant="contained">
Next
</Button>
</DialogActions>
</>
);
}
</code>
<code>const ResumeStep = ({ onNext, onCancel }) => { const [resumeList, setResumeList] = useState([]); const [selectedResume, setSelectedResume] = useState(''); const [selectedFile, setSelectedFile] = useState(null); useEffect(() => { fetchResume(); }, []); const fetchResume = async () => { try { const res = await axios.get('/api/v1/jobs/stu/resumes/'); setResumeList(res.data); } catch (error) { console.error('Error fetching resumes:', error); } }; const handleResumeChange = (event) => { setSelectedResume(event.target.value); }; const handleFileChange = (event) => { setSelectedFile(event.target.files[0]); }; const handleRemove = () => { setSelectedFile(null); }; const handleSubmit = () => { if (selectedFile) { onNext(selectedFile); } else { onNext(selectedResume); } }; return ( <> <DialogTitle>Submit Resume</DialogTitle> <FormControl fullWidth sx={{ padding: '20px' }}> <FormControl fullWidth sx={{ marginBottom: '20px' }}> <InputLabel>Select a resume</InputLabel> <Select value={selectedResume} onChange={handleResumeChange} label="Select a resume"> {resumeList.map((resume) => ( <MenuItem key={resume.id} value={resume}> {resume.name} </MenuItem> ))} </Select> </FormControl> <Divider sx={{ marginBottom: '10px' }} /> <FormControl fullWidth sx={{ padding: '20px' }}> <InputLabel>Upload a resume file</InputLabel> <Input type="file" onChange={handleFileChange} inputProps={{ accept: '.pdf,.doc,.docx' }} /> {selectedFile && selectedFile.name && ( <Typography variant="body1" sx={{ mt: 1, fontWeight: 'bold', color: 'text.primary' }}> {selectedFile.name} </Typography> )} </FormControl> </FormControl> <DialogActions> <Button onClick={onCancel} color="grey" variant="contained"> Cancel </Button> <Button onClick={handleSubmit} color="primary" variant="contained"> Next </Button> </DialogActions> </> ); } </code>
const ResumeStep = ({ onNext, onCancel }) => {
  const [resumeList, setResumeList] = useState([]);
  const [selectedResume, setSelectedResume] = useState('');
  const [selectedFile, setSelectedFile] = useState(null);


  useEffect(() => {
    fetchResume();
  }, []);

  const fetchResume = async () => {
    try {
      const res = await axios.get('/api/v1/jobs/stu/resumes/');
      setResumeList(res.data);
    } catch (error) {
      console.error('Error fetching resumes:', error);
    }
  };

  const handleResumeChange = (event) => {
    setSelectedResume(event.target.value);
  };

  const handleFileChange = (event) => {
    setSelectedFile(event.target.files[0]);
  };

  
  const handleRemove = () => {
    setSelectedFile(null);
  };

  const handleSubmit = () => {
    if (selectedFile) {
      onNext(selectedFile);
    } else {
      onNext(selectedResume);
    }
  };

  return (
    <>
      <DialogTitle>Submit Resume</DialogTitle>
      <FormControl fullWidth sx={{ padding: '20px' }}>
        <FormControl fullWidth sx={{ marginBottom: '20px' }}>
          <InputLabel>Select a resume</InputLabel>
          <Select value={selectedResume} onChange={handleResumeChange} label="Select a resume">
            {resumeList.map((resume) => (
              <MenuItem key={resume.id} value={resume}>
                {resume.name}
              </MenuItem>
            ))}
          </Select>
        </FormControl>
        <Divider sx={{ marginBottom: '10px' }} />
        <FormControl fullWidth sx={{ padding: '20px' }}>
          
          <InputLabel>Upload a resume file</InputLabel>
          
          <Input
            type="file"
            onChange={handleFileChange}
            inputProps={{ accept: '.pdf,.doc,.docx' }}
          />
          {selectedFile && selectedFile.name && (
            <Typography variant="body1" sx={{ mt: 1, fontWeight: 'bold', color: 'text.primary' }}>
              {selectedFile.name}
            </Typography>
          )}
        </FormControl>
      </FormControl>
      <DialogActions>
        <Button onClick={onCancel} color="grey" variant="contained">
          Cancel
        </Button>
        <Button onClick={handleSubmit} color="primary" variant="contained">
          Next
        </Button>
      </DialogActions>
    </>
  );
}

I have tried other methods as suggested but I am unable resolve the issue

I am trying to submit data to my api as I am doing it by selecting a resume from dropdown no such error is showing , it is also because in this case I am just passing resumeId but whenever uploading a file this error shows up

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật