import fetchJson from 'lib/fetchJson' const submitForm = async (e, url, mutateUser, setErrorMsg) => { e.preventDefault() const body = { email: e.currentTarget.email.value, password: e.currentTarget.password.value, } try { mutateUser( await fetchJson(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }) ) } catch (err) { url.includes('login') ? setErrorMsg('Could not log in') : setErrorMsg('Could not register user') } } export default submitForm