Skip to content

Improve prop validator API #8726

@znck

Description

@znck

What problem does this feature solve?

  • Allows to write validation logic depending on multiple props.
  • Allows to provide custom validation messages.

What does the proposed API look like?

type Validator = (value: any, key: string, props: Object, warn: (message: string) => void) => boolean

Example:

export default {
  props: {
    foo: {
      validator(value, key, props, warn) {
        if ('bar' in props && 'foo' in props) warn('Foo and Bar cannot be used together.')
        return true
      }
....

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions