Skip to content
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

refactor: add useEffect to additionalHooks #938

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/website/content/docs/advanced-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default [
version: "19.0.0",
importSource: "react",
additionalHooks: {
useEffect: ["useIsomorphicLayoutEffect"],
useLayoutEffect: ["useIsomorphicLayoutEffect"],
},
additionalComponents: [
Expand Down
4 changes: 3 additions & 1 deletion apps/website/content/docs/configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ For example, if you set the `additionalHooks` to:

```json
{
useEffect: ["useIsomorphicLayoutEffect"]
useLayoutEffect: ["useIsomorphicLayoutEffect"]
}
```
Expand All @@ -124,7 +125,7 @@ will be evaluated as an:
useLayoutEffect(() => { setCount(count => count + 1); }, []);
```

So that the `hooks-extra/no-direct-set-state-in-use-layout-effect` rule can perform checks on it.
So that both the `hooks-extra/no-direct-set-state-in-use-effect` and `hooks-extra/no-direct-set-state-in-use-layout-effect` rules can perform checks on it.

## Examples

Expand All @@ -142,6 +143,7 @@ export default [
importSource: "react",
polymorphicPropName: "as",
additionalHooks: {
useEffect: ["useIsomorphicLayoutEffect"],
useLayoutEffect: ["useIsomorphicLayoutEffect"],
},
additionalComponents: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ruleTester.run(RULE_NAME, rule, {
settings: {
"react-x": {
additionalHooks: {
useEffect: ["useIsomorphicLayoutEffect"],
useLayoutEffect: ["useIsomorphicLayoutEffect"],
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const ESLintReactSettingsSchema = object({
/**
* A object to define additional hooks that are equivalent to the built-in React Hooks.
* @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
* @example `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }`
* @example `{ useEffect: ["useIsomorphicLayoutEffect"] }`
*/
additionalHooks: optional(CustomHooksSchema),
/**
Expand Down Expand Up @@ -179,6 +179,7 @@ export const DEFAULT_ESLINT_REACT_SETTINGS = {
strictImportCheck: false,
version: "detect",
additionalHooks: {
useEffect: ["useIsomorphicLayoutEffect"],
useLayoutEffect: ["useIsomorphicLayoutEffect"],
},
} as const satisfies ESLintReactSettings;