I separated out an axios call into another file called ApiMethods.js.
Now, whenever I try to use the 'uploadSpecFile' function inside ApiMethods.js, I get this error:
Uncaught TypeError: Cannot read property 'then' of undefined
Here is that helper method:
export function uploadSpecFile(formData, engineId) {
return
axios({
method: 'post',
url: `/api/engineData/spec-files/${engineId}/files/upload`,
data: formData,
config: {
headers: { 'Content-Type': 'multipart/form-data' }
}
})
}
And I use it here:
import { uploadSpecFile } from '/ApiMethods';
// error occurs here **
uploadSpecFile(bodyFormData, this.props.engineId).then(response => {
this.setState({
selectedFile: response.data,
file: null
});
})
.catch(response => {
});
Is there something I'm doing wrong?
Thanks!