React Components & JSX
React components cheat sheet covering JSX syntax, props, conditional rendering, lists, event handling, and composition patterns.
Other React Sheets
Component Essentials
Core concepts for building React components
Function Components
Modern way to create React components
Basic Props
Pass data to components via props
Default Props
Set default values for optional props
Children Prop
Pass JSX content between component tags
Event Handlers
Handle user interactions with events
Component Import/Export
Organize components in separate files
Keeping Components Pure
Components must be pure functions of their props and state
JSX Fundamentals
JavaScript XML syntax for describing UI in React
JSX Basics
JavaScript XML syntax for React
JSX Expressions
Embed JavaScript expressions in JSX
JSX Attributes
HTML attributes in JSX use camelCase
Inline Styles
Apply styles using JavaScript objects
Conditional Rendering
Show/hide elements based on conditions
Lists & Keys
Render arrays with map and unique keys
Fragments
Return multiple elements without wrapper
JSX Comments
Add comments in JSX code
Forms & Controlled Components
Build interactive forms with controlled and uncontrolled components
Controlled Inputs
Form inputs controlled by React state
Form Submission
Handle form submit events
Select & Textarea
Controlled select dropdowns and textareas
Checkboxes & Radio
Handle checkbox and radio button inputs
Context API
Share data across components without prop drilling
Context API
Create, provide, and consume context with createContext and useContext
Component Patterns & Types
Advanced patterns for type safety and component composition
Composition with children
Use the children prop to build flexible, composable layout components
PropTypes & TypeScript
Add type checking to React components
Refs & forwardRef
Access DOM elements and pass refs through components
Compound Components
Build flexible APIs with related components that share state
Higher-Order Components (HOCs)
Functions that take a component and return an enhanced component
Render Props
Share logic by passing a render function as a prop
Optimization & Advanced Features
Performance optimization and advanced React features
Suspense & lazy()
Code-split components and show fallback UI while loading
Error Boundaries
Catch render errors in child components and show fallback UI
React.memo & Optimization
Optimize component re-renders with memoization
Styling Components
Different approaches to styling React components
Portals (createPortal)
Render children into a different DOM node outside the parent hierarchy
StrictMode
Catch bugs early by enabling extra development checks