React Native
Use the same form model on mobile via the gform-react/native entry point - RNGForm and RNGInput.
gform-react ships a React Native build under the gform-react/native entry point. The model is
the same - typed form, validators, formKey, the element render prop - adapted to native
components.
Import from gform-react/native
import { RNGForm, RNGInput } from "gform-react/native";The native entry exports RNGForm and RNGInput (the analogues of GForm and GInput).
Key differences from the web
React Native has no <form> element, so:
RNGFormrequires anelprop - the component to use as the form container (e.g.View).- Submission is manual - there's no native submit event. Use a button's
onPresswithstate.checkValidity(). - State has no
toFormData()-RNGFormStateexposestoRawData(),toURLSearchParams(),checkValidity(),dispatchChanges(), andisValid/isInvalid. - Fields are text-based -
RNGInput'selementreceives React NativeTextInputProps(withonChangeText/onEndEditingwired up); by default it renders a<TextInput>.
Example
import { View, Text, TextInput, Button } from "react-native";
import { RNGForm, RNGInput } from "gform-react/native";
import { GValidator, type GValidators } from "gform-react";
interface SignInForm {
username: string;
password: string;
}
const base = new GValidator().withRequiredMessage("Required");
const validators: GValidators<SignInForm> = {
"*": base,
password: new GValidator(base).withMinLengthMessage("At least 6 characters"),
};
export function SignInScreen() {
return (
<RNGForm<SignInForm> el={View} validators={validators}>
{(state) => (
<View style={{ gap: 12 }}>
<RNGInput
formKey="username"
required
element={(input, props) => (
<View>
<TextInput {...props} placeholder="username" />
{input.error && <Text style={{ color: "red" }}>{input.errorText}</Text>}
</View>
)}
/>
<RNGInput
formKey="password"
required
minLength={6}
secureTextEntry
element={(input, props) => (
<View>
<TextInput {...props} placeholder="password" />
{input.error && <Text style={{ color: "red" }}>{input.errorText}</Text>}
</View>
)}
/>
<Button
title="Sign in"
disabled={state.isInvalid}
onPress={() => {
if (state.checkValidity()) {
console.log(state.toRawData());
}
}}
/>
</View>
)}
</RNGForm>
);
}Default control
If you omit element, RNGInput renders a plain <TextInput>. Provide element whenever you need
custom layout, labels, or error display.
Validators are shared
GValidator and GValidators come from the main gform-react entry and work identically on
native - see Validation.