React
Build typed React forms with Oxform hooks and components.
Oxform React
@oxform/react provides React hooks and render-prop components over @oxform/core.
It is designed around a small set of primitives:
useFormcreates the form API.FieldanduseFieldconnect individual fields to UI controls.ArrayFieldanduseArrayFieldmanage dynamic list fields.SubscribeanduseSubscriberead selected form state.
Install
pnpm add @oxform/react zodnpm install @oxform/react zodFirst form
import { , , } from '@oxform/react';
import { } from 'zod';
const = .({
: .(),
: .().(8),
});
export function () {
const = ({
,
: {
: '',
: '',
},
});
return (
<
={ => {
.();
void .( => {
.(.);
})();
}}
>
< ={} ='email'>
{ => < ='email' {....} />}
</>
< ={} ='password'>
{ => < ='password' {....} />}
</>
< ={} ={ => ..}>
{ => < ={}>Sign in</>}
</>
</>
);
}form.submit(onSuccess, onError?) returns an async function. Invoke that
function after preventing the browser's default submit behavior. Submit
validation uses the root schema unless an error-level submit check is configured.
Next steps
Try the React playground to interact with the examples and inspect their source.