Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Last active June 16, 2019 17:57
Show Gist options
  • Save jsmanifest/b820f9c101ae399b59b3dc9049e3b6ec to your computer and use it in GitHub Desktop.
Save jsmanifest/b820f9c101ae399b59b3dc9049e3b6ec to your computer and use it in GitHub Desktop.
import React from 'react'
const FileUploader = ({ children, triggerInput, inputRef, onChange }) => {
let hiddenInputStyle = {}
// If user passes in children, display children and hide input.
if (children) {
hiddenInputStyle = {
position: 'absolute',
top: '-9999px',
}
}
return (
<div className="cursor-pointer" onClick={triggerInput}>
<input
style={hiddenInputStyle}
ref={inputRef}
type="file"
accept="image/*"
multiple
onChange={onChange}
/>
<div className="uploader">{children}</div>
</div>
)
}
export default FileUploader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment