Skip to content

Instantly share code, notes, and snippets.

@artemhp
Created August 28, 2022 05:03
Show Gist options
  • Save artemhp/02065a97d5575198c5d27e3f2b1c823d to your computer and use it in GitHub Desktop.
Save artemhp/02065a97d5575198c5d27e3f2b1c823d to your computer and use it in GitHub Desktop.
import React, { FC } from 'react';
import { useForm } from 'react-hook-form';
import { Alert } from 'react-bootstrap';
import { useMutation } from '@tanstack/react-query';
import axios from 'axios';
const Order: FC<OrderProps> = () => {
const { handleSubmit, register } = useForm();
const { mutate, isLoading, isError } = useMutation((api) =>
axios.post(`/.netlify/functions/api/letter`, api));
const onSubmit = (data) => mutate(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
{isLoading && <Alert>Submitting ... </Alert>}
{isError && <Alert>An error occurred: {error.message}</Alert>}
<input type="text" {...register('message', { required: true })} />
<button type="submit">Send Owl</button>
</form>
);
};
export default Order;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment