Skip to content

About

React Native and Expo SDK for Formclick. Send form submissions with a useFormclick() hook. No backend needed.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

@formclick/react-native

Send form submissions to Formclick from React Native and Expo apps.

It has a useFormclick() hook that tracks loading, success and error state, and an optional FormclickProvider for shared configuration. It uses React Native's built-in fetch and has no native code, so it works in Expo Go.

Installation

npm install @formclick/react-native

Get your access key from the Formclick dashboard. Every example below uses YOUR_ACCESS_KEY.

Usage

import { useState } from 'react';
import { ActivityIndicator, Button, Text, TextInput, View } from 'react-native';
import { useFormclick } from '@formclick/react-native';

export function ContactForm() {
  const [name, setName] = useState('');
  const [email, setEmail] = useState('');
  const { submit, loading, success, error } = useFormclick();

  const send = () =>
    submit({ formId: 'YOUR_ACCESS_KEY', data: { name, email } }).catch(() => {});

  return (
    <View style={{ gap: 12, padding: 16 }}>
      <TextInput placeholder="Name" value={name} onChangeText={setName} />
      <TextInput placeholder="Email" value={email} onChangeText={setEmail}
        keyboardType="email-address" autoCapitalize="none" />
      {loading ? <ActivityIndicator /> : <Button title="Send" onPress={send} />}
      {success && <Text style={{ color: 'green' }}>Sent!</Text>}
      {error && <Text style={{ color: 'red' }}>{error.message}</Text>}
    </View>
  );
}

Hook callbacks

const { submit } = useFormclick({
  onSuccess: () => Alert.alert('Sent!'),
  onError: (err) => Alert.alert('Error', err.message),
});

App-wide configuration (optional)

import { FormclickProvider } from '@formclick/react-native';

<FormclickProvider
  submitBaseUrl="https://api.formclick.io/submit"
  headers={{ 'X-App-Version': '1.2.0' }}
  onError={(err) => console.warn(err)}
>
  <App />
</FormclickProvider>

API reference

useFormclick(options?)

Returns Type Description
submit(options) (SubmitOptions) => Promise<SubmitResult> Sends a submission. Rejects on error
loading boolean true while a request is in flight
success boolean true after a successful submission
error Error | null The last error
data SubmitResult | null The last successful response
reset() () => void Resets state to idle

SubmitOptions

Property Type Description
formId string Your Formclick access key
data FormValues Field values to submit
submitUrl string? Overrides the full endpoint URL

Development

pnpm install
pnpm typecheck
pnpm build

License

MIT © Formclick

About

React Native and Expo SDK for Formclick. Send form submissions with a useFormclick() hook. No backend needed.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages