web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.8 KiB

  1. # `eslint-plugin-react-hooks`
  2. This ESLint plugin enforces the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html).
  3. It is a part of the [Hooks API](https://reactjs.org/docs/hooks-intro.html) for React.
  4. ## Installation
  5. **Note: If you're using Create React App, please use `react-scripts` >= 3 instead of adding it directly.**
  6. Assuming you already have ESLint installed, run:
  7. ```sh
  8. # npm
  9. npm install eslint-plugin-react-hooks --save-dev
  10. # yarn
  11. yarn add eslint-plugin-react-hooks --dev
  12. ```
  13. Then extend the recommended eslint config:
  14. ```js
  15. {
  16. "extends": [
  17. // ...
  18. "plugin:react-hooks/recommended"
  19. ]
  20. }
  21. ```
  22. ### Custom Configuration
  23. If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:
  24. ```js
  25. {
  26. "plugins": [
  27. // ...
  28. "react-hooks"
  29. ],
  30. "rules": {
  31. // ...
  32. "react-hooks/rules-of-hooks": "error",
  33. "react-hooks/exhaustive-deps": "warn"
  34. }
  35. }
  36. ```
  37. ## Advanced Configuration
  38. `exhaustive-deps` can be configured to validate dependencies of custom Hooks with the `additionalHooks` option.
  39. This option accepts a regex to match the names of custom Hooks that have dependencies.
  40. ```js
  41. {
  42. "rules": {
  43. // ...
  44. "react-hooks/exhaustive-deps": ["warn", {
  45. "additionalHooks": "(useMyCustomHook|useMyOtherCustomHook)"
  46. }]
  47. }
  48. }
  49. ```
  50. We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case.
  51. ## Valid and Invalid Examples
  52. Please refer to the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) documentation and the [Hooks FAQ](https://reactjs.org/docs/hooks-faq.html#what-exactly-do-the-lint-rules-enforce) to learn more about this rule.
  53. ## License
  54. MIT