Formily Core Fundamentals
БесплатноБез исполняемых скриптовНе проверенThis skill should be used when the user asks to "learn formily basics", "setup formily", "formily core concepts", "formily getting started", "formily…
от whinc★ 15 звёзд на GitHubОб этом скилле
Formily Core Fundamentals
This skill provides essential guidance for using Formily as a React form solution. Focus on understanding core concepts, setting up Formily projects, and implementing basic forms with TypeScript.
Core Concepts Overview
Formily is a performant, flexible, and extensible form solution for React. It provides:
- Schema-driven forms - Define forms through JSON schema
- Path-based value management - Access nested form values via path strings
- Powerful validation - Built-in validation with custom rules
- Fine-grained reactivity - Efficient updates and minimal re-renders
- TypeScript support - Full type safety for forms and validation
Installation and Setup
Install core Formily packages:
npm install @formily/core @formily/react @formily/validate
For TypeScript support, install types:
npm install -D @types/react @types/react-dom
Basic Form Implementation
Create a simple contact form to understand Formily fundamentals:
1. Define Form Schema
import { createForm } from '@formily/core'
const form = createForm({
initialValues: {
name: '',
email: '',
message: ''
}
})
2. Connect Form to React
import { FormProvider, createField } from '@formily/react'
// In your component
const MyForm = () => {
return (
<FormProvider form={form}>
{/* Form fields go here */}
</FormProvider>
)
}
3. Create Form Fields
import { Field } from '@formily/react'
const NameField = () => (
<Field name="name">
{(field, state) => (
<div>
<label>Name:</label>
<input
value={state.value || ''}
onChange={e => field.onInput(e.target.value)}
/>
{state.errors && <span>{state.errors}</span>}
</div>
)}
</Field>
)
Form State Management
Formily manages form state through the form instance:
Accessing Form Values
// Get all form values
const values = form.values
// Get specific field value
const name = form.values.name
// Get nested values
const address = form.values.contact.address
Setting Form Values
// Set single field
form.setValues({
name: 'John Doe'
})
// Set multiple fields
form.setValues({
name: 'John Doe',
email: '[email protected]'
})
// Set nested values
form.setValues({
'user.profile.name': 'John Doe'
})
Field State Management
// Access field state
const field = form.query('name')
const fieldValue = field.value
const fieldErrors = field.errors
const fieldTouched = field.touched
// Modify field state
form.setFieldState('name', state => {
state.value = 'New value'
state.errors = ['Error message']
})
Validation Basics
Formily provides built-in validation capabilities:
Schema Validation
import { createForm } from '@formily/core'
const form = createForm({
schema: {
type: 'object',
properties: {
name: {
type: 'string',
title: 'Name',
required: true,
'x-validator': [
{ required: true, message: 'Name is required' },
{ min: 2, message: 'Name must be at least 2 characters' }
]
},
email: {
type: 'string',
title: 'Email',
format: 'email',
'x-validator': [
{ format: 'email', message: 'Invalid email format' }
]
}
}
}
})
Custom Validation Rules
import { createForm } from '@formily/core'
const form = createForm({
validateFirst: true,
effects() {
onFieldChange('confirmPassword', ['value'], (field) => {
const password = form.values.password
const confirmPassword = field.value
if (password !== confirmPassword) {
field.errors = ['Passwords do not match']
} else {
field.errors = []
}
})
}
})
Form Submission
Handle form submission with proper validation:
const handleSubmit = async () => {
try {
// Validate entire form
await form.validate()
// Get form values
const values = form.values
console.log('Form submitted:', values)
// Reset form if needed
form.reset()
} catch (errors) {
console.error('Validation errors:', errors)
}
}
TypeScript Integration
Formily provides full TypeScript support:
Define Form Types
interface ContactForm {
name: string
email: string
message: string
}
// Create typed form
const form = createForm<ContactForm>({
initialValues: {
name: '',
email: '',
message: ''
}
})
// Access typed values
const name: string = form.values.name
Type-Safe Field Components
import { Field } from '@formily/react'
interface StringFieldProps {
name: string
label: string
placeholder?: string
}
const StringField: React.FC<StringFieldProps> = ({ name, label, placeholder }) => (
<Field name={name}>
{(field, st
Установить Formily Core Fundamentals в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл Formily Core Fundamentals?
This skill should be used when the user asks to "learn formily basics", "setup formily", "formily core concepts", "formily getting started", "formily fundamentals", "how to use formily", "formily installation", or "formily form state management".
Как установить скилл Formily Core Fundamentals?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Formily Core Fundamentals запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
patterns
Find patterns worth sharing from recent PRs and repo history, both repeats to fix and good practices worth spreading. Use when a champion wants to know what…
от Anthropiccopilot-cli-quickstart
Use this skill when someone wants to learn GitHub Copilot CLI from scratch. Offers interactive step-by-step tutorials with separate Developer and…
от GitHubvardoger-analyze
Use when the user asks to personalize the GitHub Copilot CLI assistant, adapt Copilot to their style, use vardoger, or analyze their Copilot CLI conversation…
от GitHubpolicy-lookup
Find and explain company policies in plain language. Trigger with "what's our PTO policy", "can I work remotely from another country", "how do expenses work"…
от Anthropic