Top Related Projects
🏆 Use Ant Design like a Pro!
📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
📋 React Hooks for form state management and validation (Web + React Native)
Build forms in React, without the tears 😭
🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
Quick Overview
X-Render is a powerful and flexible form rendering engine developed by Alibaba. It allows developers to create complex forms and user interfaces using JSON schemas, providing a declarative approach to form building and management.
Pros
- Highly customizable and extensible
- Supports a wide range of form components and layouts
- Integrates well with popular React-based frameworks
- Offers excellent performance for large and complex forms
Cons
- Steep learning curve for beginners
- Documentation is primarily in Chinese, which may be challenging for non-Chinese speakers
- Limited community support compared to more established form libraries
- May be overkill for simple form requirements
Code Examples
- Basic form rendering:
import FormRender from 'form-render';
const schema = {
type: 'object',
properties: {
name: {
title: 'Name',
type: 'string',
},
age: {
title: 'Age',
type: 'number',
},
},
};
const Demo = () => <FormRender schema={schema} />;
- Custom form validation:
import FormRender from 'form-render';
const schema = {
type: 'object',
properties: {
email: {
title: 'Email',
type: 'string',
format: 'email',
},
},
};
const customValidate = (formData) => {
const errors = {};
if (!formData.email.includes('@')) {
errors.email = 'Invalid email format';
}
return errors;
};
const Demo = () => <FormRender schema={schema} customValidate={customValidate} />;
- Dynamic form fields:
import FormRender, { useForm } from 'form-render';
const schema = {
type: 'object',
properties: {
type: {
title: 'Type',
type: 'string',
enum: ['personal', 'business'],
},
// Other fields will be added dynamically
},
};
const Demo = () => {
const form = useForm();
const onTypeChange = (value) => {
if (value === 'personal') {
form.setSchema({
...schema,
properties: {
...schema.properties,
ssn: { title: 'SSN', type: 'string' },
},
});
} else {
form.setSchema({
...schema,
properties: {
...schema.properties,
taxId: { title: 'Tax ID', type: 'string' },
},
});
}
};
return <FormRender form={form} schema={schema} onFieldChange={onTypeChange} />;
};
Getting Started
-
Install the package:
npm install form-render
-
Import and use in your React component:
import FormRender from 'form-render'; const schema = { type: 'object', properties: { name: { title: 'Name', type: 'string' }, email: { title: 'Email', type: 'string', format: 'email' }, }, }; const MyForm = () => { const onFinish = (formData) => console.log(formData); return <FormRender schema={schema} onFinish={onFinish} />; };
-
Customize as needed, adding validation, dynamic fields, and custom components.
Competitor Comparisons
🏆 Use Ant Design like a Pro!
Pros of pro-components
- More comprehensive set of pre-built components for enterprise applications
- Tighter integration with Ant Design ecosystem
- Better documentation and examples for complex scenarios
Cons of pro-components
- Steeper learning curve due to more complex API
- Potentially heavier bundle size for smaller projects
- Less flexibility for custom form layouts compared to x-render
Code Comparison
x-render:
<FormRender
schema={{
type: 'object',
properties: {
name: { type: 'string', title: 'Name' },
age: { type: 'number', title: 'Age' }
}
}}
onFinish={handleSubmit}
/>
pro-components:
<ProForm
onFinish={handleSubmit}
>
<ProFormText name="name" label="Name" />
<ProFormDigit name="age" label="Age" />
</ProForm>
Summary
x-render focuses on schema-driven form generation, offering a more declarative approach. It's lightweight and flexible but may require more custom work for complex scenarios.
pro-components provides a rich set of pre-built components tailored for enterprise applications. It offers more out-of-the-box functionality but comes with a steeper learning curve and potentially larger bundle size.
Choose x-render for simpler, schema-based forms with high customization needs. Opt for pro-components when building complex enterprise applications within the Ant Design ecosystem.
📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
Pros of Formily
- More comprehensive and feature-rich form solution
- Better support for complex form scenarios and large-scale applications
- Stronger TypeScript integration and type inference
Cons of Formily
- Steeper learning curve due to its complexity
- Heavier bundle size compared to x-render
- May be overkill for simple form use cases
Code Comparison
Formily:
import { createForm } from '@formily/core'
import { FormProvider, Field } from '@formily/react'
const form = createForm()
<FormProvider form={form}>
<Field name="username" component="Input" />
</FormProvider>
x-render:
import { FormRender, useForm } from 'form-render'
const form = useForm()
<FormRender
form={form}
schema={{
type: 'object',
properties: {
username: { type: 'string', title: 'Username' }
}
}}
/>
Key Differences
- Formily uses a more programmatic approach, while x-render relies on JSON schema
- Formily offers more granular control over form fields and behaviors
- x-render provides a simpler API for basic form rendering scenarios
- Formily has a larger ecosystem with additional packages for specific use cases
- x-render focuses on schema-driven form generation, making it easier for non-developers to create forms
📋 React Hooks for form state management and validation (Web + React Native)
Pros of react-hook-form
- Lightweight and performant, with minimal re-renders
- Extensive validation options out-of-the-box
- Seamless integration with TypeScript for type safety
Cons of react-hook-form
- Less opinionated, requiring more setup for complex forms
- Limited built-in UI components compared to x-render
- Steeper learning curve for advanced features
Code Comparison
react-hook-form:
import { useForm } from "react-hook-form";
const { register, handleSubmit } = useForm();
const onSubmit = data => console.log(data);
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("firstName")} />
<input type="submit" />
</form>
x-render:
import { FormRender } from "x-render";
const schema = {
type: "object",
properties: {
firstName: { type: "string", title: "First Name" }
}
};
<FormRender schema={schema} onFinish={onSubmit} />
react-hook-form focuses on providing a flexible API for form handling, while x-render emphasizes declarative form generation using JSON schemas. react-hook-form offers more granular control over form elements and validation, whereas x-render provides a higher-level abstraction for rapid form development. The choice between the two depends on the specific requirements of the project and the developer's preference for control versus convenience.
Build forms in React, without the tears 😭
Pros of Formik
- Lightweight and focused specifically on form handling
- Extensive documentation and large community support
- Seamless integration with Yup for schema validation
Cons of Formik
- Limited to form-specific functionality
- Requires more manual setup for complex form scenarios
- Less opinionated, which may lead to inconsistent implementations across projects
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>
X-Render:
import { FormRender } from '@alib/form-render';
<FormRender
schema={{
type: 'object',
properties: {
name: { type: 'string', title: 'Name' }
}
}}
onSubmit={handleSubmit}
/>
Key Differences
- Formik provides a more flexible API for custom form implementations
- X-Render offers a schema-driven approach, simplifying complex form creation
- Formik has a steeper learning curve but offers more control
- X-Render provides built-in UI components and layouts
- Formik is better suited for smaller, focused form needs
- X-Render excels in rapidly building complex, data-driven forms
Both libraries have their strengths, and the choice depends on project requirements, team expertise, and desired level of control over form implementation.
🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
Pros of Table
- More flexible and customizable for complex table scenarios
- Better performance for large datasets due to virtualization
- Stronger TypeScript support and type safety
Cons of Table
- Steeper learning curve for beginners
- Less out-of-the-box functionality for form rendering
- Requires more manual configuration for basic use cases
Code Comparison
x-render (FormRender):
<FormRender
schema={{
type: 'object',
properties: {
name: { type: 'string', title: 'Name' },
age: { type: 'number', title: 'Age' }
}
}}
onFinish={handleSubmit}
/>
Table:
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
})
return (
<table>
<tbody>
{table.getRowModel().rows.map(row => (
<tr key={row.id}>{row.getVisibleCells().map(cell => <td key={cell.id}>{cell.renderCell()}</td>)}</tr>
))}
</tbody>
</table>
)
x-render focuses on simplifying form rendering with a schema-based approach, while Table provides a more granular control over table rendering and functionality. x-render is easier to set up for basic forms, but Table offers more flexibility for complex table scenarios and better performance for large datasets.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
XRender
ä¸åå°ã表å / è¡¨æ ¼ / å¾è¡¨ãå¼ç®±å³ç¨è§£å³æ¹æ¡
ä¼å¿
- FormRenderï¼ååä¸ä¸ª input ä¸æ ·å表å
- TableRenderï¼åè®®çæ & é«åº¦çµæ´»çæç´¢å表
- ChartRenderï¼å»çå¼çå¾è¡¨ç»å¶åº
- FormGeneratorï¼ä¸åå°è¡¨åå¯è§åæ建çæå©å¨
è°å¨ä½¿ç¨?
æ´å¤å¯è§ä½¿ç¨åºæ¯ï¼ä¹å¾æ¬¢è¿æ交ï½
æ¯æ
- å¦æä½ è§å¾ XRender è¿ä¸éï¼å¯ä»¥éè¿ Star æ¥è¡¨ç¤ºä½ çå欢
- å¨å ¬å¸æ个人项ç®ä¸ä½¿ç¨ XRenderï¼å¹¶å¸®å¿æ¨å¹¿ç»ä¼ä¼´ä½¿ç¨
è´¡ç®
æ³è´¡ç®ä»£ç ã解 BUG æè æé«ææ¡£å¯è¯»æ§ï¼é常欢è¿ä¸èµ·åä¸è¿æ¥ï¼å¨æ交 PR åé 读ä¸ä¸ Contributing Guideã
æè°¢ç» XRender è´¡ç®ä»£ç çä½ ä»¬ï¼
https://user-images.githubusercontent.com/8736212/123383626-ff187a80-d5c5-11eb-803f-296762fe72d0.mp4
åè®®
- éµå¾ª MIT åè®®
- 请èªç±å°äº«åååä¸å¼æº
äºå©çç群
Star è¶å¿
Top Related Projects
🏆 Use Ant Design like a Pro!
📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
📋 React Hooks for form state management and validation (Web + React Native)
Build forms in React, without the tears 😭
🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot