use formspark
1.0.0
Formspark 的 React 挂钩。
适用于 React 和 React Native。
# NPM
npm install @formspark/use-formspark
# Yarn
yarn add @formspark/use-formspark
import React , { useState } from "react" ;
import { useFormspark } from "@formspark/use-formspark" ;
const ContactForm = ( ) => {
const [ submit , submitting ] = useFormspark ( {
formId : "your-form-id"
} ) ;
const [ message , setMessage ] = useState ( "" ) ;
return (
< form onSubmit = { async ( e ) => {
e . preventDefault ( ) ;
await submit ( { message } )
} } >
< textarea
value = { message }
onChange = { ( e ) => setMessage ( e . target . value ) }
/>
< button type = "submit" disabled = { submitting } > Send </ button >
</ form >
) ;
} ;
注意:不要弄错action url(例如https://submit-form.com/capybara
)和form id(例如capybara
),这个包只使用后者。
麻省理工学院