Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Dec 10, 2024
1 parent 6590c00 commit 82c5c5a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion www/static/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@
},
{
"code": "rules-of-hooks",
"docs": "Ensure that React/Preact hooks are only called inside component functions and not\ncalled conditionally. A hook is a function that starts with `use` prefix.\n\n### Invalid:\n\n```tsx\n// BAD: Called conditionally\nfunction Component() {\n if (cond) {\n const [count, setCount] = useState(0);\n }\n // ...\n}\n\n// BAD: Called in a loop\nfunction Component() {\n for (let i = 0; i < 10; i++) {\n const [count, setCount] = useState(0);\n }\n // ...\n}\n\n// BAD: Called after conditional return\nfunction Component() {\n if (cond) {\n return;\n }\n\n const [count, setCount] = useState(0);\n // ...\n}\n\n// BAD: Called inside event handler\nfunction Component() {\n function onClick() {\n const [count, setCount] = useState(0);\n }\n\n return <button onClick={onClick}>click me</button>;\n}\n\n// BAD: Called inside useMemo\nfunction Component() {\n const value = useMemo(() => {\n const [count, setCount] = useState(0);\n return count;\n });\n}\n\n// BAD: Called inside try/catch\nfunction Component() {\n try {\n const [count, setCount] = useState(0);\n } catch {\n const [count, setCount] = useState(0);\n }\n\n // ...\n}\n```\n\n### Valid:\n\n```tsx\nfunction Component() {\n const [count, setCount] = useState(0);\n // ...\n}\n\nfunction useCustomHook() {\n const [count, setCount] = useState(0);\n // ...\n}\n```\n",
"docs": "Ensure that React/Preact hooks are only called inside component functions and\nnot called conditionally. A hook is a function that starts with `use` prefix.\n\n### Invalid:\n\n```tsx\n// BAD: Called conditionally\nfunction Component() {\n if (cond) {\n const [count, setCount] = useState(0);\n }\n // ...\n}\n\n// BAD: Called in a loop\nfunction Component() {\n for (let i = 0; i < 10; i++) {\n const [count, setCount] = useState(0);\n }\n // ...\n}\n\n// BAD: Called after conditional return\nfunction Component() {\n if (cond) {\n return;\n }\n\n const [count, setCount] = useState(0);\n // ...\n}\n\n// BAD: Called inside event handler\nfunction Component() {\n function onClick() {\n const [count, setCount] = useState(0);\n }\n\n return <button onClick={onClick}>click me</button>;\n}\n\n// BAD: Called inside useMemo\nfunction Component() {\n const value = useMemo(() => {\n const [count, setCount] = useState(0);\n return count;\n });\n}\n\n// BAD: Called inside try/catch\nfunction Component() {\n try {\n const [count, setCount] = useState(0);\n } catch {\n const [count, setCount] = useState(0);\n }\n\n // ...\n}\n```\n\n### Valid:\n\n```tsx\nfunction Component() {\n const [count, setCount] = useState(0);\n // ...\n}\n\nfunction useCustomHook() {\n const [count, setCount] = useState(0);\n // ...\n}\n```\n",
"tags": [
"recommended",
"react",
Expand Down

0 comments on commit 82c5c5a

Please sign in to comment.