upload-apollo-client/app/components/multiple-uploader.js
Jayden Seric 6492ba8fef Componentization improvements.
- Using a new component for sections.
- Renamed “multi” to “multiple” in the uploader name, to match the input attribute “multiple”.
2017-04-09 13:13:39 +10:00

32 lines
697 B
JavaScript

import {Component} from 'react'
import {graphql, gql} from 'react-apollo'
class MultipleUploader extends Component {
handleChange = ({target}) => {
if (target.validity.valid) {
this.props
.mutate({
variables: {
files: target.files
}
})
.then(({data}) => console.log('Mutation response:', data))
}
}
render () {
return <input type='file' accept={'image/jpeg,image/png'} multiple required onChange={this.handleChange} />
}
}
export default graphql(gql`
mutation multipleUpload ($files: [Upload!]!) {
multipleUpload (files: $files) {
name
type
size
path
}
}
`)(MultipleUploader)