From JSX to React 18 features—everything you need to build clean, scalable, and performant React apps.
React has evolved rapidly—from class components to hooks, from client-side rendering to server components. Whether you're a beginner or a seasoned developer, having a compact cheatsheet can save hours of Googling and debugging. This guide by CodeClash distills the essentials of React into digestible, actionable snippets
Start with the basics:
import React from 'react';
import ReactDOM from 'react-dom/client';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
Tip: Wrap your root component in <React.StrictMode> during development to catch potential issues early.
JSX is a syntax extension that looks like HTML but compiles to React.createElement() calls.
Embed expressions like {1 + 2} or {props.name}
Must return a single parent element—use fragments (<>...</>) when needed
React apps are built from components.
Functional Components are preferred for simplicity and performance
Use destructuring for cleaner props handling
Set default props to avoid undefined errors
Pass children to make components flexible
Use PropTypes for runtime type checking
Hooks bring state and lifecycle features to functional components:
useStateManage local state
useEffectHandle side effects like API calls
useContextShare global data without prop drilling
useRefAccess DOM nodes or persist values
useReducerManage complex state logic
useMemo / useCallbackOptimize performance by memoizing values/functions
useIdGenerate consistent unique IDs
useTransition / useDeferredValueImprove responsiveness for non-urgent updates
useSyncExternalStoreSubscribe to external stores safely
useLayoutEffect / useInsertionEffectControl DOM mutations and style injection
React uses Synthetic Events for cross-browser consistency.
Use onClick, onChange, etc.
Access event object via (e) => e.target.value
Prevent default behavior with e.preventDefault()
Ternary: {isLoggedIn ? <Dashboard /> : <Login />}
Logical AND: {isOnline && <span>Online</span>}
if-else inside functions for more control
Render lists with .map() and assign unique key props. Avoid using array indices unless the list is static.
Controlled Components: Bind input value to state
Uncontrolled Components: Use ref for direct access
Use libraries like Formik or React Hook Form for complex forms
Choose your flavor:
Inline styles: { style: { color: 'red' } }
CSS Modules: import styles from './App.module.css'
Styled Components: const Button = styled.button``...``;
Tailwind CSS: Utility-first classes like "bg-blue-500"
Set up routes with:
import { BrowserRouter, Routes, Route } from 'react-router-dom';
<BrowserRouter>
<Routes>
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
Use useNavigate and useParams for navigation and dynamic routing.
Context API: Lightweight global state
Redux Toolkit: Slices, actions, reducers, DevTools
Zustand, Jotai, Recoil: Modern alternatives with minimal boilerplate
Use React.memo to prevent unnecessary re-renders
Memoize values/functions with useMemo and useCallback
Lazy load components with React.lazy() and <Suspense>
Unit Testing: React Testing Library + Jest
Integration Testing: Simulate user interactions
E2E Testing: Use Cypress or Playwright for full workflows
Use class components for error boundaries
Use ReactDOM.createPortal() for modals and tooltips
startTransition: Mark updates as non-urgent
Automatic Batching: Multiple state updates are batched
React Server Components (RSC): Used in frameworks like Next.js
Build with npm run build
Host on Vercel, Netlify, or GitHub Pages
Use .env files for environment variables
Tools: React DevTools, Redux DevTools, ESLint + Prettier
React is more than a library—it’s an ecosystem. Mastering its core concepts, hooks, and performance patterns will help you build scalable, maintainable apps. And with React 18 and server components, the future is even more exciting.
0
5
1