Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Custom hooks are just functions that use hooks. ✅ Example: import { useState, useEffect } from 'react'; function useWindowWidth() { const [width, setWidth] = useState(window.innerWidth); useEffect(() =>…
Short answer: useMemo memoizes a computed value to avoid recalculating unless dependencies change. ✅ Syntax: const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]); ✅ Use case: Avoid recalculating he…
Short answer: void recalculating heavy logic on every render. Explain a bit more const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]); void recalculat…
Short answer: useCallback memoizes a function to avoid unnecessary re-creations. ✅ Syntax: const memoizedCallback = useCallback(() => { doSomething(a, b); }, [a, b]); ✅ Use case: Prevents unnecessary re-renders of chi…
Short answer: Class Component Pitfall Hook-Based Solution this binding issues ✅ No this in hooks Boilerplate code ✅ More concise with hooks Sharing logic ✅ Custom hooks enable reuse Complex lifecycle logic ✅ useEffect un…
Short answer: Redux is a predictable state container for JavaScript apps, often used with React. ✅ Why use Redux? Centralizes app state Makes state predictable and traceable Useful in large-scale apps with deeply nested…
Short answer: Local State (useState) Global State (Redux/Context) Exists within a component Shared across multiple components Ideal for UI-level concerns Ideal for app-wide data (e.g., auth, theme) Cannot be accessed by…
Short answer: Context API is a built-in way to pass data globally without prop drilling. Feature Context API Redux Built-in? ✅ Yes ❌ No (external lib) Use case Small to medium apps Large/complex apps Boilerplate Minimal…
Short answer: sync support Manual Built-in via middleware DevTools ❌ Limited ✅ Excellent support Real-world example (ShopNest) ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, wit…
Short answer: ✅ Create context: const ThemeContext = React.createContext(); ✅ Provide context: <ThemeContext.Provider value="dark"> <App /> </ThemeContext.Provider> ✅ Consume context: const th…
Short answer: Give examples. Middleware are functions that sit between dispatching an action and reaching the reducer. ✅ Common uses: Handle async operations (API calls) Logging Error handling ✅ Examples: redux-thunk red…
Short answer: Middleware are functions that sit between dispatching an action and reaching the reducer. Explain a bit more ✅ Common uses: Handle async operations (API calls) Logging Error handling ✅ Examples: redux-thunk…
Short answer: Feature Thunks (redux-thunk) Sagas (redux-saga) Concept Functions returned from actions Generator-based side effects Complexity Simple Advanced Syntax Imperative (JS functions) Declarative (generators/yield…
Short answer: ctions Generator-based side effects Complexity Simple Advanced Syntax Imperative (JS functions) Declarative (generators/yield) Use case Basic async logic Complex flows, retries, delays ✅ Thunk const fetchUs…
Short answer: Redux Toolkit (RTK) is the official, recommended way to write Redux logic. ✅ RTK Benefits: Less boilerplate Built-in createSlice, createAsyncThunk, configureStore Integrated DevTools Handles immutability un…
Short answer: Scenario Use Simple data (theme, locale) ✅ Context API Complex global state ✅ Redux Needs middleware or DevTools ✅ Redux Only few components need data ✅ Context Large team/multiple features ✅ Redux Toolkit…
Short answer: ✅ Using middleware, such as: redux-thunk – lets you dispatch functions redux-saga – handles complex side effects via generators redux-observable – uses RxJS ✅ Example with thunk: const fetchData = () =>…
Short answer: Selectors are functions that read and return data from the store, often with memoization. Explain a bit more ✅ Purpose: Centralize access to state shape Avoid duplication Optimize performance ✅ Basic select…
Short answer: React Router is the standard library for routing in React applications. It enables navigation between different components or views without full page reloads, helping build single-page applications (SPA). D…
Short answer: Applications (SPA). Declarative routing: Allows you to define routes using JSX. Dynamic routing: Routes can be dynamically rendered based on the state, props, or URL. Real-world example (ShopNest) ShopNest’…
Short answer: You can implement routing in React using React Router. Here's how: Real-world example (ShopNest) ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for loca…
Short answer: Feature BrowserRouter HashRouter URL structure Clean URLs (e.g., /home, /about) URLs include a # (e.g., /home#about) Usage Preferred for modern apps on a web server Useful for apps without server-side routi…
Short answer: web server Useful for apps without server-side routing (e.g., static sites) History API support Uses the HTML5 history API Uses the URL's hash to manage routing SEO friendliness SEO-friendly (with server-si…
Short answer: To create nested routes, place a <Route /> inside another route's component. Explain a bit more Example: import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom'; function App()…
Short answer: You can pass URL parameters (also called dynamic routes) using : in the route path. Example: import { BrowserRouter as Router, Route, Switch, useParams } from 'react-router-dom'; function App() { return ( &…
React.js React.js Tutorial · React
Short answer: Custom hooks are just functions that use hooks. ✅ Example: import { useState, useEffect } from 'react'; function useWindowWidth() { const [width, setWidth] = useState(window.innerWidth); useEffect(() => { const handleResize = () => setWidth(window.innerWidth); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); return width;
} // Usage function Component() { const width = useWindowWidth();
return <p>Window width: {width}</p>;
}
ShopNest’s cart icon uses useState for count and useEffect to load the cart once on mount.
React.js React.js Tutorial · React
Short answer: useMemo memoizes a computed value to avoid recalculating unless dependencies change. ✅ Syntax: const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]); ✅ Use case: Avoid recalculating heavy logic on every render. const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]);
React.js React.js Tutorial · React
Short answer: void recalculating heavy logic on every render.
const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]); void recalculating heavy logic on every render. const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]); void recalculating heavy logic on every render. const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]); void recalculating heavy logic on every render. const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]);
Heavy product grids memoize row components so typing in the search box does not re-render every image card unnecessarily.
React.js React.js Tutorial · React
Short answer: useCallback memoizes a function to avoid unnecessary re-creations. ✅ Syntax: const memoizedCallback = useCallback(() => { doSomething(a, b); }, [a, b]); ✅ Use case: Prevents unnecessary re-renders of child components receiving functions as props. const handleClick = useCallback(() => { console.log("Clicked!"); }, []);
React.js React.js Tutorial · React
Short answer: Class Component Pitfall Hook-Based Solution this binding issues ✅ No this in hooks Boilerplate code ✅ More concise with hooks Sharing logic ✅ Custom hooks enable reuse Complex lifecycle logic ✅ useEffect unifies side effects ✅ Hooks lead to simpler, more readable, and reusable code. React State Management – Redux, Context API, and More
ShopNest’s cart icon uses useState for count and useEffect to load the cart once on mount.
React.js React.js Tutorial · React
Short answer: Redux is a predictable state container for JavaScript apps, often used with React. ✅ Why use Redux? Centralizes app state Makes state predictable and traceable Useful in large-scale apps with deeply nested components Works well with middleware for async tasks (like API calls)
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Local State (useState) Global State (Redux/Context) Exists within a component Shared across multiple components Ideal for UI-level concerns Ideal for app-wide data (e.g., auth, theme) Cannot be accessed by siblings Easily accessible across app
React.js React.js Tutorial · React
Short answer: Context API is a built-in way to pass data globally without prop drilling. Feature Context API Redux Built-in? ✅ Yes ❌ No (external lib) Use case Small to medium apps Large/complex apps Boilerplate Minimal More (simplified by RTK) Async support Manual Built-in via middleware DevTools ❌ Limited ✅ Excellent support
React.js React.js Tutorial · React
Short answer: sync support Manual Built-in via middleware DevTools ❌ Limited ✅ Excellent support
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: ✅ Create context: const ThemeContext = React.createContext(); ✅ Provide context: <ThemeContext.Provider value="dark"> <App /> </ThemeContext.Provider> ✅ Consume context: const theme = useContext(ThemeContext);
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Give examples. Middleware are functions that sit between dispatching an action and reaching the reducer. ✅ Common uses: Handle async operations (API calls) Logging Error handling ✅ Examples: redux-thunk redux-saga redux-logger ✅ Example (redux-logger): const logger = store => next => action => { console.log('dispatching', action); return next(action); };
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Middleware are functions that sit between dispatching an action and reaching the reducer.
✅ Common uses: Handle async operations (API calls) Logging Error handling ✅ Examples: redux-thunk redux-saga redux-logger ✅ Example (redux-logger): const logger = store => next => action => { console.log('dispatching', action); return next(action); }; Middleware are functions that sit between dispatching an action and reaching the reducer.
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Feature Thunks (redux-thunk) Sagas (redux-saga) Concept Functions returned from actions Generator-based side effects Complexity Simple Advanced Syntax Imperative (JS functions) Declarative (generators/yield) Use case Basic async logic Complex flows, retries, delays ✅ Thunk
const fetchUser = () => (dispatch) => { fetch("/api/user") .then(res => res.json()) .then(data => dispatch({ type: "SET_USER", payload: data })); };
React.js React.js Tutorial · React
Short answer: ctions Generator-based side effects Complexity Simple Advanced Syntax Imperative (JS functions) Declarative (generators/yield) Use case Basic async logic Complex flows, retries, delays ✅ Thunk const fetchUser = () => (dispatch) => { fetch("/api/user") .then(res => res.json()) .then(data => dispatch({ type: "SET_USER", payload: data… })); }; ctions… Generator-based side effects Complexity Simple Advanced Syntax…
Imperative (JS functions) Declarative (generators/yield) Use case Basic async logic Complex flows, retries, delays ✅ Thunk
const fetchUser = () => (dispatch) => { fetch("/api/user") .then(res => res.json()) .then(data => dispatch({ type: "SET_USER", payload: data })); }; ctions Generator-based side effects Complexity Simple Advanced Syntax Imperative (JS functions) Declarative (generators/yield) Use case Basic async logic Complex flows, retries, delays ✅ Thunk example: const fetchUser = () => (dispatch) => { fetch("/api/user") .then(res => res.json()) .then(data => dispatch({ type: "SET_USER", payload: data… })); }; ctions Generator-based side effects Complexity Simple Advanced Syntax Imperative (JS functions) Declarative (generators/yield) Use case Basic async logic Complex flows, retries, delays ✅ Thunk example: const fetchUser = () => (dispatch) => { fetch("/api/user") .then(res => res.json()) .then(data => dispatch({ type: "SET_USER", payload: data })); };
React.js React.js Tutorial · React
Short answer: Redux Toolkit (RTK) is the official, recommended way to write Redux logic. ✅ RTK Benefits: Less boilerplate Built-in createSlice, createAsyncThunk, configureStore Integrated DevTools Handles immutability under the hood ✅
const counterSlice = createSlice({ name: 'counter', initialState: 0, reducers: { increment: (state) => state + 1, }, }); export const { increment } = counterSlice.actions;
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Scenario Use Simple data (theme, locale) ✅ Context API Complex global state ✅ Redux Needs middleware or DevTools ✅ Redux Only few components need data ✅ Context Large team/multiple features ✅ Redux Toolkit 🎯 Rule of thumb: Use Context for simple static data, and Redux for dynamic or large-scale app state.
React.js React.js Tutorial · React
Short answer: ✅ Using middleware, such as: redux-thunk – lets you dispatch functions redux-saga – handles complex side effects via generators redux-observable – uses RxJS ✅ Example with thunk: const fetchData = () => async (dispatch) => { const response = await fetch('/data');
const data = await response.json(); dispatch({ type: 'SET_DATA', payload: data }); };
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Selectors are functions that read and return data from the store, often with memoization.
✅ Purpose: Centralize access to state shape Avoid duplication Optimize performance ✅ Basic selector: const selectUser = (state) => state.user; ✅ With reselect: import { createSelector } from 'reselect'; const selectCartItems = (state) => state.cart.items; const selectTotalPrice = createSelector( [selectCartItems], (items) => items.reduce((sum, item) => sum + item.price, 0) ); React Routing
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: React Router is the standard library for routing in React applications. It enables navigation between different components or views without full page reloads, helping build single-page applications (SPA). Declarative routing: Allows you to define routes using JSX. Dynamic routing: Routes can be dynamically rendered based on the state, props, or URL.
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Applications (SPA). Declarative routing: Allows you to define routes using JSX. Dynamic routing: Routes can be dynamically rendered based on the state, props, or URL.
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: You can implement routing in React using React Router. Here's how:
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: Feature BrowserRouter HashRouter URL structure Clean URLs (e.g., /home, /about) URLs include a # (e.g., /home#about) Usage Preferred for modern apps on a web server Useful for apps without server-side routing (e.g., static sites) History API support Uses the HTML5 history API Uses the URL's hash to manage routing SEO friendliness SEO-friendly (with server-side configuration) Less SEO-friendly due to # in the URL
React.js React.js Tutorial · React
Short answer: web server Useful for apps without server-side routing (e.g., static sites) History API support Uses the HTML5 history API Uses the URL's hash to manage routing SEO friendliness SEO-friendly (with server-side configuration) Less SEO-friendly due to # in the URL
React.js React.js Tutorial · React
Short answer: To create nested routes, place a <Route /> inside another route's component.
Example: import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom'; function App() { return ( <Router> <div> <nav> <Link to="/about/team">Team</Link> <Link to="/about/company">Company</Link> </nav> <Switch> <Route exact path="/about" component={About} /> <Route path="/about/team" component={Team} /> <Route path="/about/company" component={Company} /> </Switch> </div> </Router> ); } function About() { return <h2>About Page</h2>;
} function Team() { return <h3>Team Page</h3>;
} function Company() { return <h3>Company Page</h3>;
}
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
React.js React.js Tutorial · React
Short answer: You can pass URL parameters (also called dynamic routes) using : in the route path. Example: import { BrowserRouter as Router, Route, Switch, useParams } from 'react-router-dom'; function App() { return ( <Router> <Switch> <Route path="/user/:id" component={User} /> </Switch> </Router> ); } function User() { const { id } = useParams(); // Access the dynamic parameter
return <h1>User ID: {id}</h1>;
} In the example above, visiting /user/1 will display User ID: 1.
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.