Convert Figma logo to code with AI

vazco logouniforms

A React library for building forms from any schema.

1,938
239
1,938
34

Top Related Projects

33,863

Build forms in React, without the tears 😭

📋 React Hooks for form state management and validation (Web + React Native)

🏁 High performance subscription-based form state management for React

4,465

Performance-focused API for React forms 🚀

1,803

React High Order Form Component(web & react-native)

Quick Overview

Uniforms is a React library for building forms. It provides a set of components and utilities to create dynamic, schema-based forms with automatic validation and error handling. Uniforms aims to simplify form creation and management in React applications.

Pros

  • Supports multiple schema types (SimpleSchema, JSON Schema, GraphQL)
  • Automatic form generation based on schemas
  • Customizable form fields and layouts
  • Built-in validation and error handling

Cons

  • Learning curve for complex form scenarios
  • Limited built-in field types (though extensible)
  • Documentation could be more comprehensive
  • May be overkill for simple forms

Code Examples

  1. Basic form creation:
import { AutoForm } from 'uniforms-semantic';
import { bridge as schema } from './schema';

function MyForm() {
  return (
    <AutoForm
      schema={schema}
      onSubmit={(model) => console.log(model)}
    />
  );
}
  1. Custom field usage:
import { AutoField } from 'uniforms-semantic';

function CustomField() {
  return (
    <AutoField
      name="customField"
      component={MyCustomComponent}
    />
  );
}
  1. Form with validation:
import { ValidatedForm } from 'uniforms-semantic';
import { bridge as schema } from './schema';

function ValidatedForm() {
  return (
    <ValidatedForm
      schema={schema}
      onSubmit={(model) => console.log(model)}
      onValidate={(model, error, callback) => {
        // Custom validation logic
        callback();
      }}
    />
  );
}

Getting Started

  1. Install uniforms and a theme package:

    npm install uniforms uniforms-semantic semantic-ui-react
    
  2. Create a schema (e.g., using SimpleSchema):

    import SimpleSchema from 'simpl-schema';
    
    const schema = new SimpleSchema({
      name: String,
      age: Number,
      email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email
      }
    });
    
  3. Create a form component:

    import { AutoForm } from 'uniforms-semantic';
    import { bridge as schema } from './schema';
    
    function MyForm() {
      return (
        <AutoForm
          schema={schema}
          onSubmit={(model) => console.log(model)}
        />
      );
    }
    
  4. Use the form in your application:

    import MyForm from './MyForm';
    
    function App() {
      return (
        <div>
          <h1>My Application</h1>
          <MyForm />
        </div>
      );
    }
    

Competitor Comparisons

33,863

Build forms in React, without the tears 😭

Pros of Formik

  • More popular and widely adopted, with a larger community and ecosystem
  • Simpler API and easier to get started for basic form scenarios
  • Better integration with React's component model and hooks

Cons of Formik

  • Less flexible for complex form structures and nested data
  • Fewer built-in form controls and validation options
  • Requires more manual setup for advanced use cases

Code Comparison

Formik:

import { Formik, Form, Field } from 'formik';

<Formik initialValues={{ name: '' }} onSubmit={handleSubmit}>
  <Form>
    <Field name="name" />
    <button type="submit">Submit</button>
  </Form>
</Formik>

Uniforms:

import { AutoForm, AutoField } from 'uniforms-material';

<AutoForm schema={schema} onSubmit={handleSubmit}>
  <AutoField name="name" />
  <button type="submit">Submit</button>
</AutoForm>

Summary

Formik is more popular and easier to use for simple forms, while Uniforms offers more flexibility and built-in features for complex scenarios. Formik integrates well with React patterns, but Uniforms provides more out-of-the-box functionality. The choice between them depends on the specific requirements of your project and the complexity of your forms.

📋 React Hooks for form state management and validation (Web + React Native)

Pros of react-hook-form

  • Lightweight and performant, with minimal re-renders
  • Flexible and easy to integrate with existing form elements
  • Extensive validation options and error handling capabilities

Cons of react-hook-form

  • Steeper learning curve for complex form scenarios
  • Less opinionated, requiring more manual setup for advanced use cases
  • Limited built-in UI components compared to uniforms

Code Comparison

react-hook-form:

import { useForm } from "react-hook-form";

function MyForm() {
  const { register, handleSubmit } = useForm();
  const onSubmit = (data) => console.log(data);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("firstName")} />
      <input {...register("lastName")} />
      <button type="submit">Submit</button>
    </form>
  );
}

uniforms:

import { AutoForm, AutoField } from 'uniforms-material';
import { bridge as schema } from './schema';

function MyForm() {
  const onSubmit = (model) => console.log(model);

  return (
    <AutoForm schema={schema} onSubmit={onSubmit}>
      <AutoField name="firstName" />
      <AutoField name="lastName" />
      <button type="submit">Submit</button>
    </AutoForm>
  );
}

The code comparison shows that react-hook-form requires more manual setup but offers greater flexibility, while uniforms provides a more declarative approach with automatic form generation based on a schema.

🏁 High performance subscription-based form state management for React

Pros of react-final-form

  • More flexible and customizable, allowing for complex form structures
  • Lighter weight and faster performance due to minimal re-renders
  • Extensive documentation and large community support

Cons of react-final-form

  • Steeper learning curve, especially for beginners
  • Requires more boilerplate code for basic form setups
  • Less out-of-the-box UI components compared to uniforms

Code Comparison

react-final-form:

import { Form, Field } from 'react-final-form'

<Form
  onSubmit={onSubmit}
  render={({ handleSubmit }) => (
    <form onSubmit={handleSubmit}>
      <Field name="firstName" component="input" placeholder="First Name" />
      <button type="submit">Submit</button>
    </form>
  )}
/>

uniforms:

import { AutoForm, AutoField } from 'uniforms-material'

<AutoForm schema={schema} onSubmit={onSubmit}>
  <AutoField name="firstName" />
  <button type="submit">Submit</button>
</AutoForm>

react-final-form offers more control over form rendering and behavior, while uniforms provides a more streamlined approach with automatic form generation based on schemas. react-final-form is better suited for complex, custom forms, whereas uniforms excels in rapid development of standard forms with less code.

4,465

Performance-focused API for React forms 🚀

Pros of unform

  • Built with TypeScript, offering better type safety and developer experience
  • Supports React Native out of the box, enabling mobile app development
  • More flexible and customizable form state management

Cons of unform

  • Smaller community and ecosystem compared to uniforms
  • Less comprehensive documentation and examples
  • Steeper learning curve for beginners

Code Comparison

unform:

import { Form } from '@unform/web';
import Input from './components/Input';

function MyForm() {
  return (
    <Form onSubmit={handleSubmit}>
      <Input name="email" />
      <button type="submit">Submit</button>
    </Form>
  );
}

uniforms:

import { AutoForm } from 'uniforms-semantic';
import { schema } from './schema';

function MyForm() {
  return (
    <AutoForm schema={schema} onSubmit={handleSubmit}>
      <AutoField name="email" />
      <SubmitField />
    </AutoForm>
  );
}

Summary

unform offers more flexibility and TypeScript support, making it suitable for complex projects and mobile development. However, uniforms provides a more straightforward approach with better documentation and community support, making it easier for beginners to get started. The choice between the two depends on project requirements and developer preferences.

1,803

React High Order Form Component(web & react-native)

Pros of form

  • Simpler API with fewer concepts to learn
  • More lightweight and focused on basic form functionality
  • Better suited for simpler form use cases

Cons of form

  • Less powerful validation and error handling capabilities
  • Fewer built-in form controls and field types
  • Limited schema support compared to uniforms

Code Comparison

form:

<Form onSubmit={this.onSubmit}>
  <FormItem label="Username">
    <Input name="username" />
  </FormItem>
  <FormItem label="Password">
    <Input name="password" type="password" />
  </FormItem>
  <Button type="submit">Submit</Button>
</Form>

uniforms:

<AutoForm schema={schema} onSubmit={this.onSubmit}>
  <AutoField name="username" />
  <AutoField name="password" type="password" />
  <SubmitField />
</AutoForm>

The form example shows a more manual approach to form creation, while uniforms demonstrates its schema-driven, automatic field generation capabilities. uniforms requires less boilerplate for complex forms but may be overkill for simpler use cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vazco/uniforms

Logo

A set of React libraries for building forms from every schema.

API | Contribute | Quick Start | Playground | Roadmap

Coverage License Downloads GitHub Discussions Version Status

What's included?


License

Like every package maintained by Vazco, uniforms packages are MIT licensed.

NPM DownloadsLast 30 Days