Skip to content

Comments

React query support#10

Open
colorpulse6 wants to merge 4 commits intomainfrom
react-query-support
Open

React query support#10
colorpulse6 wants to merge 4 commits intomainfrom
react-query-support

Conversation

@colorpulse6
Copy link
Owner

No description provided.

🚀 Major new feature: Complete React Query integration for el-form

## New Hooks & Features
- ✨ useFormWithMutation: Core React Query integration with automatic error mapping
- ✨ useApiForm: Simple REST API integration for common use cases
- ✨ useMutationForm: Custom mutation function support with full React Query features
- ✨ useValidationForm: Server-side validation before submission
- ✨ useOptimisticForm: Optimistic updates with automatic rollback on error

## Error Handling System
- 🛡️ Built-in error extractors for Standard, GraphQL, Zod, and Array error formats
- 🎯 Automatic mapping from server responses to form field errors
- 🔧 Custom error extraction function support

## Documentation & Examples
- 📚 Comprehensive React Query integration guide (docs/react-query.md)
- 📖 Updated all main documentation pages with React Query references
- 🎨 Added React Query examples to examples page
- 📋 Complete implementation guide (REACT_QUERY_INTEGRATION.md)
- 🧪 Working test component with real examples

## Developer Experience
- 🔒 Full TypeScript support with generics
- 🔄 Zero breaking changes - progressive enhancement
- 📦 Modular design - each hook works independently
- ⚡ Fallback support when React Query not installed

## Documentation Updates
- Updated sidebar navigation structure
- Enhanced intro, quick-start, examples, and advanced guides
- Added cross-references and navigation flow
- Fixed sidebar positioning for all documentation pages

Enables server-side validation, mutation error handling, optimistic updates,
and seamless API integration while maintaining the clean, developer-friendly
API that el-form is known for.
@colorpulse6 colorpulse6 requested a review from Copilot July 15, 2025 10:52
@colorpulse6 colorpulse6 self-assigned this Jul 15, 2025

This comment was marked as outdated.

@colorpulse6 colorpulse6 requested a review from Copilot July 16, 2025 05:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds full React Query support to the form hooks library by introducing a core integration hook and convenient high-level APIs, updating types for root-level errors, and updating documentation and examples.

  • Introduce useFormWithMutation to wrap forms with React Query mutations
  • Add high-level hooks: useApiForm, useMutationForm, useValidationForm, and useOptimisticForm
  • Extend form state types to include "root" errors and export new hooks

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/el-form-react-hooks/src/useFormWithMutation.ts Core React Query integration hook
packages/el-form-react-hooks/src/useApiForm.ts Convenience hooks for REST, custom mutations, etc.
packages/el-form-react-hooks/src/types.ts Extended error type to support "root" entries
packages/el-form-react-hooks/src/index.ts Export new React Query–based hooks
docs/docs/examples.md Example outdated props/names updated for React Query
Comments suppressed due to low confidence (5)

docs/docs/examples.md:542

  • The useApiForm hook no longer accepts a schema prop. Rename this to validators: { onChange: userSchema } to match the actual API signature.
    schema: userSchema,

docs/docs/examples.md:543

  • useApiForm expects submitUrl and submitMethod rather than url and method. Update the example to submitUrl: "/api/users".
    url: "/api/users",

docs/docs/examples.md:562

  • The example uses form.errors, but the new API stores errors under form.formState.errors. Update references accordingly.
          {form.errors.name && (

packages/el-form-react-hooks/src/useFormWithMutation.ts:129

  • Consider adding unit tests for useFormWithMutation to verify that field and root error extraction and clearErrors on success work as intended.
export function useFormWithMutation<

packages/el-form-react-hooks/src/useFormWithMutation.ts:144

  • User-supplied onSettled callbacks in mutationOptions.mutation are not forwarded. Consider extracting and invoking mutationOptions.mutation.onSettled inside your wrapper so that custom onSettled logic is not silently ignored.
  const mutation = useMutation({

: errorExtractor;

// Default API submission function
const defaultSubmitFn = useCallback(
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useCallback dependency list includes the headers object, which may be re-created on every render if not memoized, causing unnecessary re-creations of defaultSubmitFn. Consider memoizing or allowing stable headers references.

Copilot uses AI. Check for mistakes.
…field validation

- Add useFieldQuery hook with smart debouncing and React Query integration
- Create useDebounce utility for optimized validation timing
- Add fallback implementation when React Query is not available
- Include comprehensive example with username availability checking
- Export new validation hooks from main package
- Full TypeScript support with proper error handling
- Progressive enhancement design - works with or without React Query

This establishes the foundation for query-based validation, enabling real-time
server-side field validation with caching, background sync, and excellent UX.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant