commerce icon indicating copy to clipboard operation
commerce copied to clipboard

Add form validations to the core

Open lfades opened this issue 2 years ago • 1 comments

Validations are a very important feature where we currently lack in Next.js Commerce . An ideal solution should:

  • Be opinionated, extendable, customizable, provide good defaults and be overridable
  • Update our hooks to be able to define validations for the hook, with support for custom error's messages
  • Include the same validations for API endpoints, we should validate user input in every scope
  • Keep the same hook definition, all validations and settings should be optional, same goes for API endpoints
  • Have a very small JS footprint, this is less important for API endpoints.
  • Work for custom forms. We don't intend to provide core UI components for now, but our validations should be able to work in forms

Validation considerations we currently have:

  • Manual

    Pros:

    • No external dependencies
    • Flexible implementation

    Cons

    • Verbose
    • Validation is hard
  • Superstruct (3kb)

    Pros:

    • Easier implementation

    Cons

    • Adding external dependency
    • Force providers to use this library

For Form support:

  • Manual

    Pros:

    • No external dependencies
    • Flexible implementation

    Cons

    • Implementation might be hard for some fields
    • Not performant if using connected components
  • react-final-form (3kb)

    • Easy API
    • Performant

    Cons

    • Adding external dependency
    • Force providers to use this library

lfades avatar Oct 01 '21 01:10 lfades

I guess you've seen it but just in case react-hook-form 8.3kB, big community, very performant and easy to use.

Florian-crg avatar Oct 18 '21 21:10 Florian-crg

Hey there! Thank you for opening this issue. We have decided to take Next.js Commerce in a new direction and will be closing out current PRs and issues due to this change. Please see this PR for more details: https://github.com/vercel/commerce/pull/966

leerob avatar Apr 18 '23 02:04 leerob