Debian Codegraph @

node/react-dropzone/examples/class-component/README.md

raw
1 If you're still using class components, you can use the [`<Dropzone>`](https://react-dropzone.js.org/#components) component provided by the lib:
2
3 ```jsx harmony
4 import React, {Component} from 'react';
5 import Dropzone from 'react-dropzone';
6
7 class Basic extends Component {
8 constructor() {
9 super();
10 this.onDrop = (files) => {
11 this.setState({files})
12 };
13 this.state = {
14 files: []
15 };
16 }
17
18 render() {
19 const files = this.state.files.map(file => (
20 <li key={file.name}>
21 {file.name} - {file.size} bytes
22 </li>
23 ));
24
25 return (
26 <Dropzone onDrop={this.onDrop}>
27 {({getRootProps, getInputProps}) => (
28 <section className="container">
29 <div {...getRootProps({className: 'dropzone'})}>
30 <input {...getInputProps()} />
31 <p>Drag 'n' drop some files here, or click to select files</p>
32 </div>
33 <aside>
34 <h4>Files</h4>
35 <ul>{files}</ul>
36 </aside>
37 </section>
38 )}
39 </Dropzone>
40 );
41 }
42 }
43
44 <Basic />
45 ```