npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@putout/plugin-react-hook-form

v4.0.0

Published

🐊Putout plugin adds ability to migrate to latest version of React Hook Form

Downloads

136

Readme

@putout/plugin-react-hook-form NPM version

🐊Putout plugin adds ability to migrate to latest version of React Hook Form. Not bundled.

Install

npm i putout @putout/plugin-react-hook-form -D

Add .putout.json with:

{
    "plugins": ["react-hook-form"]
}

Rules

Here is list of rules:

{
    "rules": {
        "react-hook-form/v7-apply-form-state": "on",
        "react-hook-form/v6-apply-clear-errors": "on",
        "react-hook-form/v6-convert-as-to-render": "on",
        "react-hook-form/v6-convert-form-context-to-form-provider": "on",
        "react-hook-form/v6-convert-trigger-validation-to-trigger": "on",
        "react-hook-form/v5-remove-value-from-control": "on"
    }
}

v7-apply-form-state

errors located in formState in v7. Check out in 🐊Putout Editor.

❌ Example of incorrect code

import {useForm} from 'react-hook-form';

const {errors} = useForm();

✅ Example of correct code

import {useForm} from 'react-hook-form';

const {formState} = useForm();
const {errors} = formState;

v6-apply-clear-errors

clearError was renamed to clearErrors in v6. Check out in 🐊Putout Editor.

❌ Example of incorrect code

const {
    register,
    setError,
    clearError,
    errors,
} = useForm<{}>;

✅ Example of correct code

const {
    register,
    setError,
    clearErrors,
    errors,
} = useForm<{}>;

v6-convert-as-to-render

Control has no as, it uses render starting from v6. Check out in 🐊Putout Editor.

❌ Example of incorrect code

const a = (
    <Controller
        as={CustomInput}
        valueName="textValue"
        onChangeName="onTextChange"
        control={control}
        name="test"
    />
);

✅ Example of correct code

const a = (
    <Controller
        render={({onChange, onBlur, value}) => <CustomInput onTextChange={onChange} onBlur={onBlur} textValue={value}/>}
        control={control}
        name="test"
    />
);

v6-convert-form-context-to-form-provider

FormContext was renamed to FormProvider starting from v6. Check out in 🐊Putout Editor.

❌ Example of incorrect code

import {FormContext} from 'react-hook-form';

export default () => <FormContext></FormContext>;

✅ Example of correct code

import {FormProvider} from 'react-hook-form';

export default () => <FormProvider></FormProvider>;

v6-convert-trigger-validation-to-trigger

triggerValidation was renamed no trigger, starting from v6. Check out in 🐊Putout Editor.

❌ Example of incorrect code

import {useForm} from 'react-hook-form';

const {
    register,
    triggerValidation,
    errors,
} = useForm();

triggerValidation();

✅ Example of correct code

import {useForm} from 'react-hook-form';

const {
    register,
    trigger,
    errors,
} = useForm();

trigger();

v5-remove-value-from-control

Return value of control attribute function no longer has value property in v5. Check out in 🐊Putout Editor.

❌ Example of incorrect code

import {TextInput} from 'react-native';

const a = (
    <Controller
        as={<TextInput
            style={{
                borderWidth: 2,
                borderColor: 'black',
            }}
        />}
        name="text"
        control={(args) => ({
            value: args[0].nativeEvent.text,
        })}
        onChange={onChange}
    />
);

✅ Example of correct code

import {TextInput} from 'react-native';

const a = (
    <Controller
        as={<TextInput
            style={{
                borderWidth: 2,
                borderColor: 'black',
            }}
        />}
        name="text"
        control={(args) => args[0].nativeEvent.text}
        onChange={onChange}
    />
);

License

MIT