Oxform

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:

  • useForm creates the form API.
  • Field and useField connect individual fields to UI controls.
  • ArrayField and useArrayField manage dynamic list fields.
  • Subscribe and useSubscribe read selected form state.

Install

pnpm add @oxform/react zod
npm install @oxform/react zod

First 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.