Last active
December 13, 2021 12:55
-
-
Save TheJarX/c31d58cc063d00366ce876d35f988a29 to your computer and use it in GitHub Desktop.
Sending files from React to an Apollo api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useMutation } from '@apollo/client'; | |
import SOME_MUTATION from 'path/to/your/mutation.graphql'; | |
export default function SomeForm() { | |
const [mutate] = useMutation(SOME_MUTATION); | |
const handleChange = ({ | |
target: { | |
validity, | |
files: [file], | |
}, | |
}) => validity && mutate({ variables: { file } }); | |
return (<input type="file" onChange={handleChange} />); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment