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>
);
}
}
Я пытаюсь загрузить файл и получить его при отправке формы, я предположил, что это делается с помощью атрибута ref, но когда я записываю в консоль свое «это», свойство refs пусто. Что я делаю неправильно?
Я также проверил свой компонент UserPicForm
с помощью инспектора React, раздел refs также показывает «null».