The Laws of Sparse React
The Primary Laws
- All Sparse React Laws must adhere to the Laws defined in
Sparse.md.No Exceptions. - All React specific Sparse Laws must be specified within this file.
No Exceptions.
React Specific Laws
- Every feature which requires both UI and external dependencies must be split into three layers: components/, hooks/, and services/.
No Exceptions. - Components must be JSX views only: no data fetching, no business logic.
No Exceptions. - Hooks must contain all stateful logic, side effects, and fetch requests via
TanStack.No Exceptions. - Services must be pure synchronous business logic: no
Reactimports.No Exceptions. - All object schemas must be defined in a dedicated types/ folder.
No Exceptions. - All components must use function components with hooks: no class components.
No Exceptions. - All
.tsxfiles must export a single component, named after the file.No Exceptions. useEffectmust only be used for external systems: data fetching, subscriptions, timers.No Exceptions.- Replace internal
useEffectcases with derived state, memoization, orTanStack.No Exceptions. - All react components which require properties must declare props using an interface at the top of the file, named
[ComponentName]Props.No Exceptions. - Always destructure and pass props explicitly for your own components: never use
...restparameters.No Exceptions. - If an event handler does more than a single function call, it must be extracted into a separate function.
No Exceptions. - Every mapped element must have a stable, unique key derived from data, never array indexes.
No Exceptions. - Components must use no more than one level of ternary operators for conditional rendering.
No Exceptions.
No Exceptions.