Getting started with React
1. Install and import the @botpoison/browser library.
npm install @botpoison/browser
2. Create a new Botpoison instance with your public key.
3. Process a challenge using the challenge() function.
4. Forward the solution to your server for verification.
jsx
import React, { useState } from "react";import axios from "axios";// 1. Import the libraryimport Botpoison from "@botpoison/browser";// 2. Create a new instance with your public keyconst botpoison = new Botpoison({publicKey: "pk_xxxxxxxx"});const Form = () => {const [message, setMessage] = useState("");const onSubmit = async (e) => {e.preventDefault();// 3. Process a challengeconst { solution } = await botpoison.challenge();await axios.post("https://example.demo", {message,// 4. Forward the solution_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;