Skip to content

Instantly share code, notes, and snippets.

@TheJarX
Last active December 13, 2021 12:55
Show Gist options
  • Save TheJarX/c31d58cc063d00366ce876d35f988a29 to your computer and use it in GitHub Desktop.
Save TheJarX/c31d58cc063d00366ce876d35f988a29 to your computer and use it in GitHub Desktop.
Sending files from React to an Apollo api
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