Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); Re…
Short answer: Library (for testing React components). Real-world example (ShopNest) ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state. Say this in the…
Short answer: Use the Profiler tab to measure the render times and identify slow components. Check for unnecessary re-renders and optimize with React.memo or shouldComponentUpdate. Real-world example (ShopNest) ShopNest’…
Short answer: (Don’t call hooks inside loops, conditions, or nested functions.) Real-world example (ShopNest) ShopNest’s cart icon uses useState for count and useEffect to load the cart once on mount. Say this in the int…
Short answer: import { render } from '@testing-library/react'; import MyComponent from './MyComponent'; test('matches snapshot', () => { const { asFragment } = render(<MyComponent />); expect(asFragment()).toMat…
Short answer: import { render, screen, waitFor } from '@testing-library/react'; import MyComponent from './MyComponent'; test('fetches and displays data', async () => { global.fetch = jest.fn(() => Promise.resolve(…
Short answer: Log the time it takes for certain parts of your app to render and pinpoint slow areas. Real-world example (ShopNest) Heavy product grids memoize row components so typing in the search box does not re-render…
Short answer: (ES6+) and JSX syntax in React. Real-world example (ShopNest) ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state. Say this in the intervi…
Short answer: const server = express(); server.get('*', (req, res) => { const content = ReactDOMServer.renderToString(<App />); res.send(` <html> <head><title>SSR Example</title></head…
Short answer: Example: class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error) { return { hasError: true }; // Update st…
Short answer: wait waitFor(() => screen.getByText('Data loaded')); expect(screen.getByText('Data loaded')).toBeInTheDocument(); }); Here, we mock the fetch function to return mock data, then test whether it appears in…
Short answer: update only the items that have changed. update only the items that have changed. Real-world example (ShopNest) When rendering cart lines, use a stable key={item.id} —not the array index—so React updates th…
Short answer: import React, { Suspense } from 'react'; const LazyComponent = React.lazy(() => import('./LazyComponent')); function App() { return ( <Suspense fallback={<div>Loading...</div>}> <Laz…
Short answer: import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; function App() { return ( <Router> <Switch> <Route exact path="/" component={Home} /> <Route path=&q…
Short answer: function counterReducer(state = 0, action) { switch (action.type) { case 'INCREMENT': return state + 1; default: return state; } } Example code function counterReducer(state = 0, action) { switch (action.ty…
Short answer: (functional components or custom hooks) React enforces these rules with a linter: eslint-plugin-react-hooks. Real-world example (ShopNest) ShopNest’s cart icon uses useState for count and useEffect to load…
Short answer: JSX – JavaScript + XML Components – Reusable and composable Virtual DOM – Efficient DOM updates Unidirectional data flow – One-way data binding Lifecycle methods (in class components) Hooks (in functional c…
Short answer: sure to account for the most recent state. Real-world example (ShopNest) ShopNest’s cart icon uses useState for count and useEffect to load the cart once on mount. Say this in the interview Define — one cle…
Short answer: These libraries help solve problems like global namespace conflicts and style collisions in large React applications, allowing for scoped, dynamic styles. Real-world example (ShopNest) ShopNest’s storefront…
Short answer: Scoped CSS that helps avoid name collisions. import styles from './App.module.css'; function App() { return <div className={styles.container}>Hello, world!</div>; Real-world example (ShopNest) S…
Short answer: making sure your code follows a consistent style. Real-world example (ShopNest) ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state. Say t…
Short answer: Example: import { render, screen, fireEvent } from '@testing-library/react'; import MyComponent from './MyComponent'; test('renders the component and interacts', () => { render(<MyComponent />); co…
Short answer: If using hooks, make sure you are providing the correct dependencies to useEffect and useMemo, and avoid unnecessary recalculations. Real-world example (ShopNest) ShopNest’s cart icon uses useState for coun…
Short answer: the items that are visible in the viewport. Example of list optimization with key: const List = ({ items }) => { return ( <ul> {items.map(item => ( <li key={item.id}>{item.name}</li>…
Short answer: import { createStore } from 'redux'; const store = createStore(counterReducer); Example code import { createStore } from 'redux'; const store = createStore(counterReducer); Real-world example (ShopNest) Pro…
React.js React.js Tutorial · React
Short answer: xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock data' }); xios.get.mockResolvedValue({ data: 'mock 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: Library (for testing React components).
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: Use the Profiler tab to measure the render times and identify slow components. Check for unnecessary re-renders and optimize with React.memo or shouldComponentUpdate.
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: (Don’t call hooks inside loops, conditions, or nested functions.)
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: import { render } from '@testing-library/react'; import MyComponent from './MyComponent'; test('matches snapshot', () => { const { asFragment } = render(<MyComponent />); expect(asFragment()).toMatchSnapshot(); }); asFragment() captures the rendered output as a DOM snapshot.
toMatchSnapshot() compares the output to a previously saved snapshot. The first time the test is run, it saves the output to a snapshot file. On subsequent runs, it compares the output to the saved snapshot. If there are any changes, the test will fail. Advanced React Concepts
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: import { render, screen, waitFor } from '@testing-library/react'; import MyComponent from './MyComponent'; test('fetches and displays data', async () => { global.fetch = jest.fn(() => Promise.resolve({ json: () => Promise.resolve({ message: 'Data loaded' }), }) ); render(<MyComponent />); await waitFor(() => screen.getByText('Data loaded')); expect(screen.getByText('Data loaded')).toBeInTheDocument(); }); Here, we…
mock the fetch function to return mock data, then test whether it appears in the component.
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: Log the time it takes for certain parts of your app to render and pinpoint slow areas.
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: (ES6+) and JSX syntax in React.
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: const server = express(); server.get('*', (req, res) => { const content = ReactDOMServer.renderToString(<App />); res.send(` <html> <head><title>SSR Example</title></head> <body> <div id="root">${content}</div> </body> </html> `); }); server.listen(3000, () => console.log('Server running on In this setup, React renders the app to HTML on the server, then the client "hydrates" it for interactivity.
and making it interactive. Example with express and React: const express = require('express');
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const App = require('./App');
When rendering cart lines, use a stable key={item.id}—not the array index—so React updates the right row after delete.
React.js React.js Tutorial · React
Short answer: Example: class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error) { return { hasError: true }; // Update state to trigger a fallback UI } componentDidCatch(error, info) { console.error("Error caught by Error Boundary:", error, info); } render() { if (this.state.hasError) { return <h1>Something went wrong!</h1>; }…
return this.props.children; } } export default ErrorBoundary; You can wrap parts of your app in this ErrorBoundary to gracefully handle errors.
Example: class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false };
} static getDerivedStateFromError(error) { return { hasError: true }; // Update state to trigger a fallback UI } componentDidCatch(error, info) { console.error("Error caught by Error Boundary:", error, info); } render() { if (this.state.hasError) {
return <h1>Something went wrong!</h1>;
}
return this.props.children;
}
} export default ErrorBoundary; You can wrap parts of your app in this ErrorBoundary to gracefully handle errors.
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: wait waitFor(() => screen.getByText('Data loaded')); expect(screen.getByText('Data loaded')).toBeInTheDocument(); }); Here, we mock the fetch function to return mock data, then test whether it appears in the component.
wait waitFor(() => screen.getByText('Data loaded')); expect(screen.getByText('Data loaded')).toBeInTheDocument(); }); Here, we mock the fetch function to return mock data, then test whether it appears in the component. wait waitFor(() => screen.getByText('Data loaded')); expect(screen.getByText('Data loaded')).toBeInTheDocument(); }); Here, we mock the fetch function to return mock data, then test whether it appears in the component.
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: update only the items that have changed. update only the items that have changed.
When rendering cart lines, use a stable key={item.id}—not the array index—so React updates the right row after delete.
React.js React.js Tutorial · React
Short answer: import React, { Suspense } from 'react'; const LazyComponent = React.lazy(() => import('./LazyComponent')); function App() { return ( <Suspense fallback={<div>Loading...</div>}> <LazyComponent /> </Suspense> ); } React.lazy enables dynamic imports for code splitting. Suspense lets you specify a loading state while waiting for the component to load.
ProductCard receives price via props. The parent Catalog owns selected filters in state and passes them down.
React.js React.js Tutorial · React
Short answer: import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; function App() { return ( <Router> <Switch> <Route exact path="/" component={Home} /> <Route path="/about" component={About} /> </Switch> </Router> ); }
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: function counterReducer(state = 0, action) { switch (action.type) { case 'INCREMENT': return state + 1; default: return state; } }
function counterReducer(state = 0, action) { switch (action.type) { case 'INCREMENT': return state + 1; default: return state;
}
}
ProductCard receives price via props. The parent Catalog owns selected filters in state and passes them down.
React.js React.js Tutorial · React
Short answer: (functional components or custom hooks) React enforces these rules with a linter: eslint-plugin-react-hooks.
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: JSX – JavaScript + XML Components – Reusable and composable Virtual DOM – Efficient DOM updates Unidirectional data flow – One-way data binding Lifecycle methods (in class components) Hooks (in functional components)
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: sure to account for the most recent state.
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: These libraries help solve problems like global namespace conflicts and style collisions in large React applications, allowing for scoped, dynamic styles.
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: Scoped CSS that helps avoid name collisions. import styles from './App.module.css'; function App() { return <div className={styles.container}>Hello, world!</div>;
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: making sure your code follows a consistent style.
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: Example: import { render, screen, fireEvent } from '@testing-library/react'; import MyComponent from './MyComponent'; test('renders the component and interacts', () => { render(<MyComponent />); const button = screen.getByText('Click me'); fireEvent.click(button); expect(screen.getByText('Clicked!')).toBeInTheDocument(); });
import { render, screen, fireEvent } from '@testing-library/react'; import MyComponent from './MyComponent'; test('renders the component and interacts', () => { render(<MyComponent />); const button = screen.getByText('Click me'); fireEvent.click(button); expect(screen.getByText('Clicked!')).toBeInTheDocument(); });
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: If using hooks, make sure you are providing the correct dependencies to useEffect and useMemo, and avoid unnecessary recalculations.
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: the items that are visible in the viewport. Example of list optimization with key: const List = ({ items }) => { return ( <ul> {items.map(item => ( <li key={item.id}>{item.name}</li> ))} </ul> ); };
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: import { createStore } from 'redux'; const store = createStore(counterReducer);
import { createStore } from 'redux'; const store = createStore(counterReducer);
ProductCard receives price via props. The parent Catalog owns selected filters in state and passes them down.