React Configuration
Configure React support with JS Style Kit
Overview
JS Style Kit provides comprehensive React support with both ESLint rules and TypeScript integration. This includes support for React hooks, React Compiler, and Next.js projects.
Enabling React Support
React support is disabled by default. To enable it, specify react: true
in your ESLint configuration:
Configuration Options
The React configuration supports several options:
Function Style for Components
The functionStyle
option affects how React components are styled:
Examples of Different Function Styles
Arrow Function Style (default)
Function Declaration Style
Function Expression Style
React Compiler Support
React Compiler (formerly Forget) is a compiler that optimizes React components for better performance. JS Style Kit includes support for React Compiler through the eslint-plugin-react-compiler
plugin.
React Compiler support is enabled by default when React support is enabled. To explicitly control it:
Next.js Support
For Next.js projects, enable the next
option:
This will add .next
to the list of ignored directories, preventing ESLint from analyzing the Next.js build output.
TypeScript Integration
When both React and TypeScript are enabled, JS Style Kit automatically configures TypeScript-specific React rules:
React Hooks Rules
JS Style Kit includes the following rules for React hooks:
react-hooks/rules-of-hooks
: Enforces the Rules of Hooksreact-hooks/exhaustive-deps
: Verifies the dependency array of useEffect and similar hooks
Best Practices
The React configuration enforces several best practices:
- Consistent function component definitions
- Proper use of React.Fragment
- Proper use of useState hook
- No array indexes as keys
- Proper use of boolean props
- Self-closing tags for components without children
- And many more
These rules help avoid common pitfalls in React development and ensure consistent code style across your project.