Skip to content

Instantly share code, notes, and snippets.

@epifanov-sergey
Created Jun 16, 2019
Embed
What would you like to do?
640187-react-dropzone
import React, { createRef } from "react";
import Dropzone from "react-dropzone";
const dropzoneStyle = {
width: "200px",
height: "200px",
background: "red",
borderWidth: 2,
borderColor: "rgb(102, 102, 102)",
borderStyle: "dashed",
borderRadius: 5,
};
withAttacher.propTypes = {}; // nothing is descending
export default function withAttacher(Component) {
return class extends React.Component {
constructor(props) {
super(props);
this.dropzoneRef = createRef();
}
render() {
return (
<Dropzone style={dropzoneStyle} ref={this.dropzoneRef} multiple={false}>
{({ getInputProps }) => (
<React.Fragment>
<input {...getInputProps()} />
<Component
{...this.props}
handleClick={() => {
this.dropzoneRef.current.open();
}}
/>
</React.Fragment>
)}
</Dropzone>
);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment