score:1
Accepted answer
looks like the error is being thrown in that line:
e.target.files[0]
it's because e.target.files can be null - for instance, if you open the select file window and click cancel. i suggest you to check against null value and not to setstate if there is no files selected:
onchangehandler(e) {
if(!e.target.files) {
return;
}
this.setstate({
audio: e.target.files[0],
image: e.target.files[1],
name: e.target.value
});
}
Source: stackoverflow.com
Related Query
- Error when uploading multiple files in React
- Error when importing JSX files from another package in monorepo with React
- S3 creating empty files when uploading a file from React contact form using Axios
- Getting 415 error when trying to pass in multiple arguments to a get request in React with axios
- Unable to locate react static files when serving from django staticfiles and uploading to heroku
- Using progress handler when uploading files to AWS S3 with React
- Nginx conflicts static files when serving multiple React apps
- JavaScript CORS error when uploading files with Axios
- resolve-url-loader error when using image in jsx files in React Application
- Error when uploading image to firebase using react js
- When uploading React app to server all routes except "/" return Internal Server Error
- Django/React/Firebase - CORS error when uploading big files
- weird error shows up when moving files from path to another - firebase storage- react js-redux
- Uploading multiple files using Django & React
- How can I use components in multiple files when adding React to a website?
- What happens when using this.setState multiple times in React component?
- "React.Children.only expected to receive a single React element child" error when putting <Image> and <TouchableHighlight> in a <View>
- Cannot find namespace 'ctx' error when creating Context with react - typescript
- window not defined error when using extract-text-webpack-plugin React
- React Router BrowserRouter leads to "404 Not Found - nginx " error when going to subpage directly without through a home-page click
- React component render is called multiple times when pushing new URL
- React New Context API - Access Existing Context across Multiple Files
- Error when deploying react app and it keeps sayings << Plugin "react" was conflicted between "package.json » eslint-config-react-app » >>
- Importing multiple files in react
- Is there any way to see names of 'fields' in React multiple state with React DevTools when using 'useState' hooks
- react native how to call multiple functions when onPress is clicked
- How does webpack handle multiple files importing the same module React
- Getting an "Access Denied" error when I reload my React app on AWS Amplify
- React Native + Jest EMFILE: too many open files error
- Is it a good design, when a React Flux store emits multiple kinds of events?
More Query from same tag
- How to pass React component as regular JS to react-test-renderer
- Writing embeddable Javascript plugin with React & Webpack
- How to read the current URL in the react application
- Add thead row to Antd table component
- Changing the state of a React Component
- react prop passing to child component only works with localhost backend
- Using .map function for two dimensional array - React
- How do you inspect a react element's props & state in the console?
- Sharing actions and reducers with react/redux
- Rendering ReactJS from asynchronous server side data calls
- ReactJS question about arrays in state and the async of it
- Why .map, .length is not working on array, when it's printing an array
- React JS multiple filter by buttons
- React JS - Clear child forms on Tab clicks
- React currentTarget.selectedOptions[0].value is failing in IE 10 after <select> onChange event
- Playing local mp3 files with react js without importing
- How do I solve Error importing a css file with next.js?
- How do I deploy a React app and a Rails API to Heroku?
- When using ES6, how can an imported function be undefined in one file, and not in another?
- How to map over a JSON response in React
- React-Bootstrap Table with dynamic Content - Form over Radio Buttons in Rows not working
- amchart bullet change background color by mouse hover
- How to connect reactjs file with css
- react-carousel-slider doesn't rerender
- using relative addressing for API inside Axios request
- React.js: convert string to an object
- React - list element text not getting displayed
- For a React + TypeScript variable: enforce some attributes in the "props" of a component
- Make multiple pages in ReactJS without using react-dom-router
- React pass props down to all descendant Components