import React, { useState } from "react";
import axios from "axios";
import Botpoison from "@botpoison/browser";
const botpoison = new Botpoison({
publicKey: "pk_xxxxxxxx"
});
const Form = () => {
const [message, setMessage] = useState("");
const onSubmit = async (e) => {
e.preventDefault();
const { solution } = await botpoison.challenge();
await axios.post("https://example.demo", {
message,
_botpoison: solution,
});
alert("Form submitted");
};
return (
<form onSubmit={onSubmit}>
<textarea value={message} onChange={(e) => setMessage(e.target.value)} />
<button type="submit">Send</button>
</form>
);
};
export default Form;