# @firecms/formex

> Formex is a lightweight, flexible library designed to simplify form handling within React applications. By leveraging React's powerful context and hooks features, Formex allows for efficient form state management with minimal boilerplate code.

Latest version **3.5.1** (published 2026-09-30) · 0 weekly downloads

## Install

```sh
npm install @firecms/formex
pnpm add @firecms/formex
yarn add @firecms/formex
bun add @firecms/formex
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.5.1 |
| Published | 2026-09-30 |
| First published | 2024-02-12 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 124.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1281 |
| Maintainers | gatti675 |
| Keywords | firebase, cms, admin, admin panel, firebase panel, firestore, headless, headless cms, content manager |

## Links

- npm: https://www.npmjs.com/package/@firecms/formex
- Repository: https://github.com/firecmsco/firecms
- Homepage: https://github.com/firecmsco/firecms#readme
- Issues: https://github.com/firecmsco/firecms/issues
- npm.io page: https://npm.io/package/@firecms/formex

## Dependencies (2)

- [react-fast-compare](https://npm.io/package/react-fast-compare.md) ^3.2.2
- [react-compiler-runtime](https://npm.io/package/react-compiler-runtime.md) ^19.0.0-beta-af1b7da-20250417

## Recent versions

- 3.5.1 (latest) — 2026-09-30
- 3.5.2-canary.c5764a3 (canary) — 2026-10-13
- 3.0.0-canary.297 (pre) — 2026-01-13
- 3.5.2-canary.16bf7bb — 2026-10-13
- 3.5.0 — 2026-09-29
- 3.4.0-canary.00f9be5 — 2026-09-16
- 3.4.0-canary.9408c41 — 2026-09-16
- 3.4.0-canary.ce97da7 — 2026-09-16
- 3.4.0-canary.1faa2a9 — 2026-09-15
- 3.4.0 — 2026-08-26
- 3.4.0-canary.cb27f16 — 2026-08-26
- 3.4.0-canary.2575a08 — 2026-08-25
- 3.4.0-canary.cfeed0b — 2026-08-25
- 3.4.0-canary.e2466ba — 2026-08-03
- 3.4.0-canary.d20cc85 — 2026-08-01
- … 367 more at https://npm.io/package/@firecms/formex/versions

## README

# Formex - React Form Library

Formex is a lightweight, flexible library designed to simplify form handling within React applications. By leveraging React's powerful context and hooks features, Formex allows for efficient form state management with minimal boilerplate code.

## Features

- Lightweight and easy to integrate
- Supports custom field components
- Built-in validation handling
- Provides both field-level and form-level state management

## Installation

To install Formex, you can use either npm or yarn:

```sh
npm install @firecms/formex

# or if you're using yarn

yarn add @firecms/formex
```

## Quick Start

To get started with Formex, you first need to create your form context and form controller using the `useCreateFormex` hook. Then, you can structure your form using the `<Field />` components provided by Formex.

### Step 1: Create your form controller

```jsx
import React from 'react';
import { useCreateFormex } from 'formex-library';

const MyForm = () => {
    const formController = useCreateFormex({
        initialValues: {
            name: '',
            email: '',
        },
        // Optionally add a validation function
        // validation: values => {
        //   const errors = {};
        //   if (!values.name) errors.name = 'Name is required';
        //   return errors;
        // },
        onSubmit: (values) => {
            console.log('Form Submitted:', values);
        },
    });

    return (
        <form onSubmit={formController.handleSubmit}>
            {/* Field components go here */}
        </form>
    );
};
```

### Step 2: Use the `<Field />` component

```jsx
import { Field } from 'formex-library';

// Inside your form component
<Field name="name">
  {({ field }) => (
    <input
      {...field}
      placeholder="Your name"
    />
  )}
</Field>

<Field name="email">
  {({ field }) => (
    <input
      {...field}
      type="email"
      placeholder="Your email"
    />
  )}
</Field>

<button type="submit">Submit</button>
```

### Handling Submissions

Wrap your form inputs and submit button within a form element and pass the `submitForm` method from your form controller to the form's `onSubmit` event:

```jsx
<form onSubmit={formController.handleSubmit}>
    {/* Fields and submit button */}
</form>
```

## API Reference

### `useCreateFormex`

Hook to create a form controller.

**Parameters**

- `initialValues`: An object with your form's initial values.
- `initialErrors` (optional): An object for any initial validation errors.
- `validation` (optional): A function for validating form data.
- `validateOnChange` (optional): If `true`, validates fields whenever they change.
- `onSubmit`: A function that fires when the form is submitted.


### `<Field />`

A component used to render individual form fields.

**Props**

- `name`: The name of the form field.
- `as` (optional): The component or HTML tag that should be rendered. Defaults to `"input"`.
- `children`: A function that returns the field input component. Receives field props as its parameter.

**Example**

```jsx
<Field name="username">
  {({ field }) => <input {...field} />}
</Field>
```

## Customization

Formex is designed to be flexible. You can create custom field components, use any validation library, or integrate with UI component libraries.

### Using with UI Libraries

```jsx
import { Field } from 'formex-library';
import { TextField } from 'some-ui-library';

<Field name="username">
  {({ field }) => (
    <TextField {...field} label="Username" />
  )}
</Field>
```

### Custom Validation

Leverage the `validation` function in `useCreateFormex` to integrate any validation logic or library.

```jsx
const validate = values => {
  const errors = {};
  if (!values.email.includes('@')) {
    errors.email = 'Invalid email';
  }
  return errors;
};
```

## Conclusion

Formex provides a simple yet powerful way to manage forms in React applications. It reduces the amount of boilerplate code needed and offers flexibility to work with custom components and validation strategies. Whether you are building simple or complex forms, Formex can help streamline your form management process.

For further examples and advanced usage, refer to the Formex documentation or source code.

---
_Source: https://npm.io/package/@firecms/formex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
