Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
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 ( &…
Short answer: Feature Link NavLink Purpose Navigate between pages Navigation with active styling Active style No built-in active style Automatically adds an active class when the route is active Use case Basic navigation…
Short answer: ctive style No built-in active style utomatically adds an active class when the route is ctive Use case Basic navigation For creating navigation menus with active links (e.g., highlighting the active link)…
Short answer: Protected routes are used to restrict access to certain routes based on some condition (e.g., user authentication). You can create a wrapper component that checks the condition and either redirects or rende…
Short answer: And either redirects or renders the requested route. import { Redirect, Route } from 'react-router-dom'; function ProtectedRoute({ component: Component, ...rest }) { const isAuthenticated = false; // Replac…
Short answer: You can navigate programmatically using the useHistory hook (React Router v5) or useNavigate hook (React Router v6). For React Router v5 (useHistory): import { useHistory } from 'react-router-dom'; function…
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.
React.js React.js Tutorial · React
Short answer: Feature Link NavLink Purpose Navigate between pages Navigation with active styling Active style No built-in active style Automatically adds an active class when the route is active Use case Basic navigation For creating navigation menus with active links (e.g., highlighting the active link) Example of NavLink: import { NavLink } from 'react-router-dom'; function Navbar() { return ( <nav> <NavLink to="/"…
activeClassName="active">Home</NavLink> <NavLink to="/about" activeClassName="active">About</NavLink> </nav> ); }
React.js React.js Tutorial · React
Short answer: ctive style No built-in active style utomatically adds an active class when the route is ctive Use case Basic navigation For creating navigation menus with active links (e.g., highlighting the active link) Example of NavLink: import { NavLink } from 'react-router-dom'; function Navbar() { return ( <nav> <NavLink to="/"… ……… activeClassName="active">Home</NavLink> <NavLink to="/about"…
activeClassName="active">About</NavLink> </nav> ); } ctive style No built-in active style utomatically adds an active class when the route is ctive Use case Basic navigation For creating navigation menus with active links (e.g., highlighting the active link) Example of NavLink: import { NavLink } from 'react-router-dom'; function Navbar() { return ( <nav> <NavLink to="/" activeClassName="active">Home</NavLink> <NavLink to="/about" activeClassName="active">About</NavLink> </nav> ); } ctive style No built-in active style utomatically adds an active class when the route is ctive Use case Basic navigation For creating navigation menus…
React.js React.js Tutorial · React
Short answer: Protected routes are used to restrict access to certain routes based on some condition (e.g., user authentication). You can create a wrapper component that checks the condition and either redirects or renders the requested route.
import { Redirect, Route } from 'react-router-dom'; function ProtectedRoute({ component: Component, ...rest }) { const isAuthenticated = false; // Replace with your auth logic return ( <Route {...rest} render={(props) => isAuthenticated ? ( <Component {...props} /> ) : ( <Redirect to="/login" /> } /> ); } function App() { return ( <Router> <Switch> <Route path="/login" component={Login} /> <ProtectedRoute path="/dashboard" component={Dashboard} /> </Switch> </Router> ); } In this example, if the user is not authenticated, they will be redirected to the login page when trying to access the /dashboard route.
React.js React.js Tutorial · React
Short answer: And either redirects or renders the requested route. import { Redirect, Route } from 'react-router-dom'; function ProtectedRoute({ component: Component, ...rest }) { const isAuthenticated = false; // Replace with your auth logic return ( <Route {...rest} render={(props) => isAuthenticated ? And either redirects or renders the requested route.
import { Redirect, Route } from 'react-router-dom'; function ProtectedRoute({ component: Component, ...rest }) { const isAuthenticated = false; // Replace with your auth logic return ( <Route {...rest} render={(props) => isAuthenticated ? nd either redirects or renders the requested route. Example: import { Redirect, Route } from 'react-router-dom'; function ProtectedRoute({ component: Component, ...rest }) { const isAuthenticated = false; // Replace with your auth logic return ( <Route {...rest} render={(props) => isAuthenticated ? ( <Component {...props} /> ) : ( <Redirect to="/login" /> } /> ); } function App() { return ( <Router> <Switch> <Route path="/login" component={Login} /> <ProtectedRoute path="/dashboard" component={Dashboard} /> </Switch> </Router> ); } In this example, if the user is not authenticated, they will be redirected to the login page when trying to access the /dashboard route. nd either redirects or renders the requested route. Example: import { Redirect, Route } from 'react-router-dom'; function ProtectedRoute({ component: Component, ...rest }) { const isAuthenticated = false; // Replace with your auth logic return ( <Route {...rest} render={(props) => isAuthenticated ? ( <Component {...props} /> ) : ( <Redirect to="/login" /> } /> ); } function App() { return ( <Router> <Switch> <Route path="/login" component={Login} /> <ProtectedRoute path="/dashboard" component={Dashboard} /> </Switch> </Router> ); } In this example, if the user is not authenticated, they will be redirected to the login page when trying to access the /dashboard route.
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 navigate programmatically using the useHistory hook (React Router v5) or useNavigate hook (React Router v6). For React Router v5 (useHistory): import { useHistory } from 'react-router-dom'; function MyComponent() { const history = useHistory(); const goToHome = () => { history.push('/'); }; return <button onClick={goToHome}>Go to Home</button>;
}
For React Router v6 (useNavigate): import { useNavigate } from 'react-router-dom'; function MyComponent() { const navigate = useNavigate(); const goToHome = () => { navigate('/'); }; return <button onClick={goToHome}>Go to Home</button>;
} React Performance Optimization
ShopNest’s storefront is React: components for ProductCard, CartDrawer, and CheckoutForm, with hooks for local UI state.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.