- What is React?
React is a JavaScript library for building user interfaces, mainly used for creating single-page applications with a component-based architecture. - What are the key features of React?
- Component-based architecture
- Virtual DOM
- Unidirectional data flow
- Reusable components
- JSX syntax
- Component-based architecture
- What is JSX?
JSX (JavaScript XML) is a syntax extension for JavaScript that allows writing HTML-like code inside JavaScript. - Why use React instead of plain JavaScript?
React simplifies UI building with reusable components, improves performance with the Virtual DOM, and ensures predictable state management. - What are components in React?
Components are reusable, self-contained pieces of UI. They can be functional or class-based. - What is the difference between functional and class components?
- Functional components: Use functions, rely on Hooks for state and lifecycle.
- Class components: Use ES6 classes, have lifecycle methods and state.
- Functional components: Use functions, rely on Hooks for state and lifecycle.
- What is the Virtual DOM?
A lightweight copy of the real DOM. React updates the Virtual DOM first, then compares it with the previous version (diffing), and only updates the real DOM where necessary. - What are props in React?
Props (properties) are used to pass data from parent to child components. They are read-only. - What is state in React?
State is a built-in object in React that stores component data and controls how components render and behave. - What is the difference between state and props?
- Props: Passed from parent, immutable.
- State: Managed inside the component, mutable.
- What are React lifecycle methods?
Special methods in class components that run at different stages: mounting, updating, and unmounting. - What are the lifecycle phases?
- Mounting (constructor, render, componentDidMount)
- Updating (shouldComponentUpdate, render, componentDidUpdate)
- Unmounting (componentWillUnmount)
- What replaces lifecycle methods in functional components?
React Hooks like useEffect. - When is componentDidMount() used?
Runs after the component is mounted; useful for API calls or subscriptions. - When is componentWillUnmount() used?
Runs before a component is removed; used for cleanup like removing event listeners.
- What are React Hooks?
Functions that allow functional components to use state and lifecycle features. - What are the most used Hooks?
- useState
- useEffect
- useContext
- useReducer
- useRef
- useMemo
- useCallback
- What is useState?
Hook to declare state variables in functional components. - What is useEffect?
Hook to handle side effects (API calls, DOM manipulation, subscriptions). - Difference between useEffect and lifecycle methods?
useEffect combines componentDidMount, componentDidUpdate, and componentWillUnmount. - What is useContext?
Hook that provides access to context data without using props drilling. - What is useReducer?
Alternative to useState for complex state logic. Works like Redux reducer. - What is useRef?
Hook that creates mutable references that don’t trigger re-renders (used for accessing DOM nodes). - What is useMemo?
Hook for memoizing values to avoid unnecessary recalculations. - What is useCallback?
Hook for memoizing functions to prevent unnecessary re-renders.
- What is React Fiber?
A reimplementation of React’s reconciliation algorithm for better UI rendering. - What is reconciliation in React?
The process of updating the DOM by comparing the new Virtual DOM with the previous one. - What is keys in React lists?
Keys help React identify elements when rendering lists. They should be unique and stable. - What is lifting state up?
Moving state to a common ancestor to share data between child components. - What is controlled vs uncontrolled components?
- Controlled: Form data is handled by React state.
- Uncontrolled: Form data handled by the DOM using ref.
- What is React Fragments?
<React.Fragment> lets you return multiple elements without adding extra DOM nodes. - What is React Portal?
A way to render children into a DOM node outside the parent hierarchy. - What is error boundary?
Special component that catches JavaScript errors in child components. - What is code splitting in React?
Breaking code into smaller bundles to improve performance, often using React.lazy and Suspense. - What is lazy loading in React?
Dynamically loading components only when needed.
- What is Redux?
A state management library based on a single store and predictable state updates. - Core principles of Redux?
- Single source of truth
- State is read-only
- Pure reducers handle state changes
- What are reducers in Redux?
Pure functions that take current state and action, return new state. - What are actions in Redux?
Plain JavaScript objects describing what to do (type + payload). - What is Redux middleware?
Functions that run between dispatching an action and reaching the reducer. - What is Redux Thunk?
Middleware for handling async actions. - Difference between Redux and Context API?
- Redux: Better for large apps, middleware, debugging.
- Context API: Lightweight, suitable for small/medium apps.
- What is the Redux store?
Central place that holds the entire app state. - How to connect React with Redux?
Using react-redux with Provider, useSelector, and useDispatch. - What is the difference between useSelector and useDispatch?
- useSelector: Read state from store.
- useDispatch: Dispatch actions to update store.
- How to optimize React performance?
- Memoization (React.memo, useMemo, useCallback)
- Code splitting
- Avoid anonymous functions in render
- Virtualization (e.g., react-window)
- Using keys properly
- What is React.memo?
Higher-order component that memoizes functional components to avoid unnecessary re-renders. - What is shouldComponentUpdate()?
Lifecycle method in class components to prevent unnecessary re-renders. - What is useTransition in React 18?
Hook for handling concurrent UI updates smoothly. - What is suspense in React?
Allows components to wait for async data before rendering.
- What is React Router?
A library for handling routing in React applications. - Difference between BrowserRouter and HashRouter?
- BrowserRouter: Uses HTML5 history API.
- HashRouter: Uses URL hash (#) for routing.
- What are Route and Switch?
- Route: Renders a component for a path.
- Switch: Renders only the first matching route.
- What is useNavigate in React Router v6?
Hook to navigate programmatically. - What is dynamic routing?
Creating routes based on dynamic parameters (e.g., /user/:id).
- What is Jest?
A JavaScript testing framework for unit tests. - What is React Testing Library (RTL)?
A testing library focused on testing React components from a user perspective. - Difference between shallow and mount in Enzyme?
- Shallow: Renders component without children.
- Mount: Renders full DOM including children.
- How to test asynchronous code in React?
Using async/await with waitFor in RTL. - How to test React hooks?
Use @testing-library/react-hooks or test components that use hooks.
- What is Concurrent Rendering?
React can interrupt rendering for better UI responsiveness. - What is useDeferredValue?
Hook for deferring expensive calculations while keeping UI responsive. - What is automatic batching in React 18?
Groups multiple state updates into one re-render automatically. - What is Server Components in React?
Components rendered on the server to reduce client-side JavaScript. - What is streaming SSR in React 18?
Server-side rendering that streams HTML progressively.
- What is Flux architecture?
Pattern where data flows in a single direction via actions, dispatcher, store, and views. - What is the difference between React and Angular?
- React: Library, virtual DOM, flexible.
- Angular: Framework, two-way data binding, opinionated.
- What is the difference between React and Vue?
- React: Uses JSX, flexible ecosystem.
- Vue: Template-based, simpler learning curve.
- What are higher-order components (HOC)?
Functions that take a component and return an enhanced component. - What are render props?
A technique where a component’s children is a function that controls rendering. - What is prop drilling?
Passing props through multiple levels of components unnecessarily. - What is the solution for prop drilling?
Context API or Redux. - What is hydration in React?
Attaching event listeners to server-rendered HTML on the client side. - What is React Native?
Framework for building mobile apps using React. - What is difference between CSR and SSR?
- CSR: Rendering happens in the browser.
- SSR: Rendering happens on the server.
- How can you style components in React?
- Inline styles
- CSS stylesheets
- CSS Modules
- Styled-components (CSS-in-JS)
- Tailwind CSS or other utility libraries
- What are CSS Modules in React?
A way to scope CSS locally to components, avoiding global class conflicts. - What are styled-components?
A CSS-in-JS library allowing you to write CSS inside JavaScript using template literals. - Difference between inline styles and CSS Modules?
- Inline styles: Written directly in JSX.
- CSS Modules: Written in .module.css files, scoped locally.
- Can React work without CSS?
Yes, React only manages UI logic. Styling is optional, but usually CSS (or CSS-in-JS) is used. - How to handle forms in React?
- Controlled components (with state)
- Uncontrolled components (with ref)
- What is two-way data binding in React?
React does not have two-way binding by default. Instead, controlled components achieve similar results by updating state on input changes. - How to validate forms in React?
- Custom validation with state
- Libraries like Formik or React Hook Form
- What is synthetic event in React?
A wrapper around browser events that works the same across different browsers. - How to handle multiple inputs in React forms?
Use name attributes and update state dynamically with [e.target.name]: e.target.value.
- What is Next.js?
A React framework for server-side rendering, static site generation, and routing. - What is Gatsby.js?
A React framework for building static websites with GraphQL. - What is React Query?
A library for fetching, caching, and synchronizing server state in React. - What is Recoil in React?
A state management library for managing global state with atoms and selectors. - What is React DevTools?
A browser extension for debugging React components, props, and state.
- How do you build a React app for production?
Using npm run build or yarn build which creates optimized static files. - How to deploy a React app?
- Netlify
- Vercel
- GitHub Pages
- AWS, Azure, or Firebase hosting
- What is tree shaking in React?
Process of removing unused code from the final bundle. - What is source maps in React?
Files that map minified code to original source code for debugging. - What are environment variables in React?
Variables like API keys stored in .env files, accessed via process.env.
- How to prevent XSS (Cross-Site Scripting) in React?
React escapes content by default. For raw HTML, use dangerouslySetInnerHTML carefully. - What is dangerouslySetInnerHTML?
A React prop that lets you set HTML directly into the DOM. It must be sanitized to avoid XSS. - How to secure API keys in React apps?
Do not expose keys in frontend. Use backend proxy or serverless functions. - What is CSRF and how to prevent it in React apps?
Cross-Site Request Forgery; prevent using CSRF tokens and same-site cookies. - What are best security practices in React?
- Escape data properly
- Use HTTPS
- Avoid inline scripts
- Use authentication & authorization properly
- Regular dependency updates