question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Add `rule` to the return value of `useForm()`

See original GitHub issue

Add rule to the return value of useForm(), so that I can validate a value before assigning it into form:

const { 
    form, 
    rule, // new
} = useForm({
    form: () => {
        return {
           foo: ''
        }
    },
    rule: {
        foo: (v) => !!v.length || 'Foo required!',
    },
})

const myFoo = 'bar'
const isMyFooValid = rule.foo.validate(myFoo) // true
if (isMyFooValid) {
    form.foo = myFoo
}

I think it can be more flexible and convenient in some cases.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xuzuodongcommented, Nov 28, 2022

Thanks so much for your quick response! 😄 @LittleSound

0reactions
LittleSoundcommented, Nov 28, 2022

I have re-released v0.8.0 and it should be fine now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useForm | React Hook Form - Simple React forms validation
This option allows you to configure the validation strategy before a user submits the form that is happened during onSubmit event by invoking...
Read more >
Advanced Usage - React Hook Form
React Hook Form has support for native form validation, which lets you validate inputs with your own rules. Since most of us have...
Read more >
useForm - register - Simple React forms validation
This method allows you to register an input or select element and apply validation rules to React Hook Form. Validation rules are all...
Read more >
useForm - reset - React Hook Form
Rules. For controlled components you will need to pass defaultValues to useForm in order to reset the Controller components' value.
Read more >
useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and have the options to validate and update the form...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found