import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';
export default class UserPicForm extends React.Component {
constructor() {
super();
// bindings
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
event.preventDefault();
let file = this;
console.log('this is the file', file);
}
render() {
return (
<Form onSubmit={this.handleSubmit}>
<FormGroup>
<Label for="exampleFile">Upload Image</Label>
<Input ref={(ref) => this.fileUpload = ref} type="file" name="file" id="exampleFile" />
<FormText color="muted">
Please use the field above to upload your profile picture.
</FormText>
</FormGroup>
<Button type="submit">Upload</Button>
</Form>
);
}
}
I am trying to upload a file and grab it on form submit, I assumed this is done with ref attribute but when I console log my 'this' the refs property is empty. What am I doing wrong?
I also inspected my UserPicForm component using React inspector, the refs section is showing 'null' as well.