React Cheatsheet & Component Cheat Sheet
Ultimate React cheatsheet and development hooks cheat sheet. Master core state management, side effects, Context API providers, and memoization hacks.
Interactive Skill Mastery
Mark commands as learned to build your customized reference tracker. Retained locally in this browser.
Core Hooks
When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const [state, setState] = useState(initialValue);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
useEffect(() => {\n console.log("Mounted");\n return () => console.log("Unmounted");\n}, [deps]);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const ref = useRef(null);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const [state, dispatch] = useReducer(reducer, initialState);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
useLayoutEffect(() => {\n // Measure DOM before screen paint\n}, []);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const state = useSyncExternalStore(subscribe, getSnapshot);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.Custom Hooks
When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
function useWindowWidth() {\n const [width, setWidth] = useState(window.innerWidth);\n // ... subscribe to resize events\n return width;\n}Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const id = useId();Output Example
Component mounted successfully, updating active DOM node branches in the browsers.Context API
When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const ThemeContext = createContext("light");\n// ...\nconst currentTheme = useContext(ThemeContext);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.Component Structure
When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const MyComponent: React.FC<Props> = ({ title, children }) => {\n return <h1>{title}</h1>;\n};Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const LazyComp = React.lazy(() => import("./LazyComp"));Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
useImperativeHandle(ref, () => ({\n focus: () => { inputRef.current.focus(); }\n}));Output Example
Component mounted successfully, updating active DOM node branches in the browsers.Performance
When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const memoizedValue = useMemo(() => computeValue(a, b), [a, b]);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const memoizedCallback = useCallback(() => handleClick(id), [id]);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
export default React.memo(MyComponent);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const [isPending, startTransition] = useTransition();Output Example
Component mounted successfully, updating active DOM node branches in the browsers.When to Use
When developing interactive web user interfaces, functional components, or stateful client-side logic states.
Common Mistakes
Mutating local React states directly rather than using standard hooks setter triggers, or skipping dependencies in arrays.
Shortcut / Pro-Tip
Always keep state objects modular and cleanly separate your side-effects to preserve quick Virtual DOM rendering cycles.Example
const deferredValue = useDeferredValue(value);Output Example
Component mounted successfully, updating active DOM node branches in the browsers.React Best Practices
1Optimize Re-renders with useMemo
Wrap compute-heavy calculations inside useMemo hooks to bypass repeating calculations on every component paint cycle.
2Provide Explicit Dependency Arrays
Never leave dependency arrays blank unless you want effects to run on every render. Use primitive values in arrays to prevent infinite render loops.
3Adopt Functional Component Patterns
Stick strictly to functional components and React Hooks, ensuring maximum efficiency, clean state management, and lifecycle handling.
4Abstract Logic into Custom Hooks
Keep visual components highly readable by extracting complex state logic, subscriptions, or async tasks into custom hooks.
5Manage Keys on Dynamic Lists Rigorously
Always apply unique, persistent keys (never random values or array index counts if list ordering is dynamic) to list loops so React can reconcile DOM tree nodes.
Common React Errors & Solutions
Too many re-renders. React limits the number of renders
You are setting state directly within your component rendering body. Move state updates inside useEffect or standard event handlers.
React Hooks must be called in the exact same order
Ensure hooks are only declared at the top-level of functional components. Never put hooks inside conditions, loops, or nested functions.
State update is not reflected immediately
React state setters are asynchronous. Access the updated value by passing a functional updater (prev => prev + 1) or inside a useEffect tracking the state.
Can't perform a React state update on an unmounted component
Cancel any active asynchronous fetches, timers, or subscriptions within the useEffect cleanup function.
Props read-only violation error
Props are completely immutable. If values need to change, trigger parent callbacks to update the state variable inside the parent component.
Common React Interview Questions
Q1What are React Hooks and what rules must they follow?
Hooks are functions that let functional components manage state and side effects. Rules: 1. Only call hooks at the top level of your component (never inside loops, conditions, or nested functions). 2. Only call hooks from React functional components or custom hooks.
Q2What is the purpose of useEffect, and how does the cleanup function work?
useEffect handles side effects (APIs, subscriptions, manual DOM edits). The returned cleanup function runs right before the component unmounts or before the effect runs again, letting you clear timers and subscriptions.
Q3What is React Virtual DOM and how does reconciliation work?
The Virtual DOM is an in-memory representation of the real DOM. When state changes, React builds a new virtual tree, compares it with the previous one (diffing), and patches only the changed nodes in the real DOM (reconciliation).
Q4What is the difference between useMemo and useCallback?
useMemo caches and returns the computed result of an expensive calculation function. useCallback caches and returns the actual function reference itself, preventing child components from re-rendering due to fresh function instances.
Q5Explain the React Context API and its use case.
Context API provides a way to pass data down the component tree without manually passing props at every level (props drilling). It is ideal for global state setups like language, themes, or user authentications.
Related Resources
REST API Tester
Test API routes and endpoints directly in your browser with full request controls.
JSON Formatter & Validator
Beautify, validate, and minify JSON structures instantly.
Best Free Online Developer Tools
An expert review of must-have online utilities for developers.
Git Cheatsheet
Essential command reference for local and remote version control repositories.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com