-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add rules_of_hooks rule #1346
Conversation
function Component() { | ||
const [count, setCount] = useState(0); | ||
// ... | ||
} | ||
|
||
function useCustomHook() { | ||
const [count, setCount] = useState(0); | ||
// ... | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this one to show all "bad" examples written in a correct form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the only correct ones for all bad examples.
if let Some(ch) = name.chars().next() { | ||
return ch.is_uppercase(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this hit? Could you add a small unit test for this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hit in pretty much all bad variants. It tests if the enclosing function is a component.
Co-authored-by: Bartek Iwańczuk <[email protected]>
Co-authored-by: Bartek Iwańczuk <[email protected]>
170903f
to
f34cead
Compare
This PR implements the
rules-of-hooks
eslint rule, see https://react.dev/reference/rules/rules-of-hooks . It ensures that hooks are only used inside components and that they are called unconditionally.