Skip to content

Commit

Permalink
Merge pull request #2 from brocoders/feat/new-rules-for-eslint
Browse files Browse the repository at this point in the history
feat: new rules for react-hook-form
  • Loading branch information
Shchepotin authored Sep 20, 2023
2 parents cad68d3 + 1bb8e0c commit 3a8a31b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
"selector": "CallExpression[callee.name=watch], MemberExpression[object.name=methods][property.name=watch]",
"message": "\"watch\" re-render the whole form component. Use hook \"useWatch\" instead."
},
{
"selector": "VariableDeclarator > ObjectPattern > Property[key.name=formState]",
"message": "\"formState\" re-render the whole form component. Use hook \"useFormState\" instead."
},
{
"selector": "VariableDeclarator[init.callee.name=useFormState][id.type=Identifier]",
"message": "Use destructuring assignment for \"useFormState\". Example: \"const { isDirty } = useFormState()\". Returned formState is wrapped with Proxy to improve render performance and skip extra computation if specific state is not subscribed, so make sure you deconstruct or read it before render in order to enable the subscription. More info here https://react-hook-form.com/docs/useformstate#rules"
},
{
"selector": "MemberExpression[object.name=control]",
"message": "Do not access any of the properties inside this object directly. It's for internal usage only. More info here: https://react-hook-form.com/docs/useform/control"
},
{
"selector": "VariableDeclaration[declarations.0.init.callee.name=useForm] ~ VariableDeclaration[declarations.0.init.callee.name=useWatch]",
"message": "\"useWatch\" in main form component (which use \"useForm\") will re-render the whole form component. Move your useWatch's logic to separate component."
Expand Down

0 comments on commit 3a8a31b

Please sign in to comment.