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
const keyToSnake = word => word.replace( | |
/[A-Z]+/, | |
match => `_${match.toLowerCase().split('').join('_')}`, | |
); | |
const toSnakeCase = (obj) => { | |
const entries = Object.entries(obj).map( | |
entry => [keyToSnake(entry[0]), entry[1]], | |
); |
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], |
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
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types | |
// you can return an array instead of an object | |
function getDataFromMIME(mime) { | |
const [type, subtype, parameter] = mime.split(/[\/\;]/); | |
const [paramName, paramValue] = parameter.split('='); | |
return { | |
type, | |
subtype, | |
[paramName]: paramValue, | |
parameter: [paramName, paramValue] |