Skip to content

Instantly share code, notes, and snippets.

@epifanov-sergey
Created June 16, 2019 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epifanov-sergey/8ac420bfce99f4a4f681563acbce2cc6 to your computer and use it in GitHub Desktop.
Save epifanov-sergey/8ac420bfce99f4a4f681563acbce2cc6 to your computer and use it in GitHub Desktop.
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