consolelog.tools

Custom Hook Tester

Analyze React hooks for best practices, issues, and generate Vitest scaffolding

About this ToolHow it works, benefits & use cases

Paste a custom React hook and this analyzer statically lints it for the mistakes that bite later, then scaffolds a test file. It checks that the function name follows the use-prefix convention and is detectable at all, looks for the React import, and inspects useEffect calls — warning about a missing dependency array (which runs the effect every render), noting an empty array (mount-only), and suggesting a cleanup function when effects might set up subscriptions or timers. It also watches for potential state updates during render, confirms the hook returns something, and nudges you toward TypeScript annotations and JSDoc. Results are grouped into issues, warnings, and suggestions. A second button generates a React Testing Library scaffold — renderHook and act with describe blocks for initial values, state updates, unmount cleanup, and edge cases — named from your hook. It analyses the code you paste, in the browser, with no execution.

How to Use

  1. 1Paste your full custom hook source — including imports — into the input box, or click "Load example".
  2. 2Click "Analyze Hook" to lint it for naming, effect, return, and typing issues.
  3. 3Read the grouped results: issues to fix, warnings to review, and optional suggestions.
  4. 4Click "Generate Vitest Scaffold" to produce a renderHook-based test file named after your hook.
  5. 5Copy or download the generated test scaffold into a .test.ts file beside your hook.

Key Benefits

  • Static analysis with no code execution — your hook source stays in the browser
  • Verifies the use-prefix naming convention and detects the hook declaration
  • Flags useEffect with no dependency array and notes empty (mount-only) arrays
  • Suggests cleanup functions and warns on possible state updates during render
  • Checks for a return value, TypeScript annotations, and JSDoc documentation
  • Groups findings into issues, warnings, and suggestions for quick triage
  • Generates a React Testing Library test scaffold tailored to your hook name

Common Use Cases

  • Reviewing a teammate's custom hook for missing dependency arrays or cleanup
  • Sanity-checking your own hook before opening a pull request
  • Bootstrapping a renderHook test file so you do not start from a blank page
  • Catching the use-prefix and return-value mistakes that break the rules of hooks
  • Teaching common custom-hook pitfalls with concrete, copyable feedback

Paste the full hook source including imports.

Copy into a .test.ts file alongside your hook.

Click 'Generate Vitest Scaffold' to see test boilerplate.

What We Check

  • Hook naming convention (must start with "use")
  • Proper dependency arrays in useEffect
  • Cleanup functions in effects
  • TypeScript type annotations
  • Return values and documentation

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools