Technical interview Q&A plus 100+ career & HR questions—notice period, salary negotiation, resume, LinkedIn, freelancing, AI careers, and behavioral interviews with detailed, real-world answers.
40 MCQs per stack · 80% pass · certificate + per-question feedback
40 questions · 60 min · Pass 80%
Start practice exam40 questions · 60 min · Pass 80%
Start practice exam40 questions · 60 min · Pass 80%
Start practice examReact.js React.js Tutorial · React
pplications. It helps developers create reusable UI components, manage state efficiently,
nd update the UI in a performant way.
✅ Why use React?
React.js React.js Tutorial · React
(Don’t call hooks inside loops, conditions, or nested functions.)
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: props change. If not properly optimized, this can lead to performance bottlenecks. Example: A large component tree where every small state change causes re-renders for the entire tree.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Library (for testing React components).
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
xios.get.mockResolvedValue({ data: 'mock data' });
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
ReactDOMServer.renderToString().
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: ssets. It’s highly configurable and can be used for React apps, though tools like CRA automate this.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: You can import regular CSS files directly into your components. import './App.css'; // Regular CSS file
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
styled based on props or state.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
i18next library to manage translation strings and locale settings.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Fetch) to authenticate and get a token.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
on the server. This allows search engines to crawl the content.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
dependencies can lead to bugs or infinite loops.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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)
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: (functional components or custom hooks) React enforces these rules with a linter: eslint-plugin-react-hooks.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: function counterReducer(state = 0, action) { switch (action.type) { case 'INCREMENT': return state + 1; default: return state; } }
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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>
);
}React.js React.js Tutorial · React
time it takes for React to render.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
import React, { Suspense } from 'react';
const LazyComponent = React.lazy(() => import('./LazyComponent'));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
);
}
React.js React.js Tutorial · React
update only the items that have changed.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
component. Never call hooks inside loops, conditions, or nested functions.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
fireEvent() to simulate user interaction.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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.
React.js React.js Tutorial · React
nd 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');
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.React.js React.js Tutorial · React
(ES6+) and JSX syntax in React.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: function Home() { return <h1>Home Page</h1>; } function About() { return <h1>About Page</h1>; }
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: If using hooks, make sure you are providing the correct dependencies to useEffect and useMemo, and avoid unnecessary recalculations.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
understand the context of your content.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
JSX stands for JavaScript XML. It lets you write HTML-like syntax in JavaScript.
const element = <h1>Hello, world!</h1>;
🚫 No, browsers cannot read JSX directly. JSX needs to be transpiled (e.g., using
Babel) into regular JavaScript.
React.js React.js Tutorial · React
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();
});
React.js React.js Tutorial · React
Answer: Scoped CSS that helps avoid name collisions. import styles from './App.module.css'; function App() { return <div className={styles.container}>Hello, world!</div>; }
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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> ); };
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
import { createStore } from 'redux'; const store = createStore(counterReducer);
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
sure to account for the most recent state.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
making sure your code follows a consistent style.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
rendered or a function is called.
Example of a simple unit test:
import { render, screen, fireEvent } from '@testing-library/react';
import Counter from './Counter';
test('increments counter on button click', () => {
render(<Counter />);
const button = screen.getByText('Increment');
fireEvent.click(button);
expect(screen.getByText('1')).toBeInTheDocument();
});
In this test, you:
React.js React.js Tutorial · React
the render method, it can block the UI thread, resulting in slow rendering.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: These libraries help solve problems like global namespace conflicts and style collisions in large React applications, allowing for scoped, dynamic styles.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
internationalization.
Example with react-i18next:
npm install react-i18next i18next
import { useTranslation } from 'react-i18next';
function MyComponent() {
const { t } = useTranslation();
return <h1>{t('welcome_message')}</h1>;
}
In this case, t('welcome_message') will fetch the corresponding translation for the
current language set in your app.
React.js React.js Tutorial · React
Answer: Feature React Angular Vue Type Library (UI focused) Framework (full-featured) Framework (lightweight) DOM Handling Virtual DOM Real DOM Virtual DOM Data Binding One-way Two-way Both supported Learning Curve Medium Steep Easy
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: optimization can degrade performance, especially if each item is re-rendered every time the parent changes.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Example:
function App() {
const isAuthenticated = localStorage.getItem('authToken');
return isAuthenticated ? <Dashboard /> : <Login />;
}
For handling OAuth or third-party login (e.g., with Google or Facebook), you might use a
library like Firebase or Auth0.
React.js React.js Tutorial · React
manipulating the DOM when it’s unnecessary) can lead to performance issues.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Use performance monitoring tools like why-did-you-render to detect unnecessary re-renders in functional components. Example: npm install @welldone-software/why-did-you-render Testing React Components
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: state changes frequently or if the shouldComponentUpdate method isn’t properly utilized.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Many of these tools are integrated automatically when you use CRA or Next.js, but they can be configured or customized in more advanced setups.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
engines.
Example (with react-helmet):
import { Helmet } from 'react-helmet';
function MyPage() {
return (
<div>
<Helmet>
<title>My SEO Optimized Page</title>
<meta name="description" content="Description of my page for
SEO" />
</Helmet>
<h1>Welcome to My SEO Page</h1>
</div>
);
}React.js React.js Tutorial · React
or effects that trigger multiple renders. ⚙ Miscellaneous React Concepts
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Components are the building blocks of a React application. Each component is an isolated, reusable piece of the UI. ✅ Example: function Welcome(props) { return <h1>Hello, {props.name}</h1>; }
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
import styled from 'styled-components';
const Button = styled.button`
background: ${(props) => (props.primary ? 'blue' : 'gray')};
color: white;
`;
function App() {
return <Button primary={true}>Click Me</Button>;
}React.js React.js Tutorial · React
Feature Class
Component
Functional
Component
Syntax ES6 Class Function
State this.state useState hook
Lifecycle methods Yes Use useEffect, etc.
Code size More verbose Cleaner and shorter
✅ Example:
Class:
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Functional:
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}React.js React.js Tutorial · React
Answer: JSX can create new function references on every render, causing unnecessary re-renders.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
The Virtual DOM is a lightweight in-memory representation of the real DOM. React
updates the Virtual DOM first and compares it with the previous version, only applying the
necessary changes to the real DOM.
✅ Benefit: Improves performance by reducing real DOM operations.
React.js React.js Tutorial · React
React’s reconciliation algorithm compares the new Virtual DOM with the old one using a
diffing algorithm. It:
React.js React.js Tutorial · React
Answer: Props (short for "properties") are read-only data passed from a parent component to a child. ✅ Example: function Greeting(props) { return <h1>Hello, {props.name}!</h1>; } <Greeting name="Alice" />
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Utility-first CSS framework that uses predefined classes for layout and styling. Great for rapid development.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
State is data that is local to a component and can change over time.
✅ Example using useState:
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count +
1)}>{count}</button>;
}React.js React.js Tutorial · React
Answer: Functional component: Use setState from useState. Class component: Use this.setState(). ✅ Example: const [name, setName] = useState("John"); setName("Doe");
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Feature Props State Mutable? ❌ No (read-only) ✅ Yes Who sets it? Parent component Component itself Used for Passing data Handling internal data
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Keys help React identify which items have changed, been added, or removed. ✅ Example: {items.map(item => ( <li key={item.id}>{item.name}</li> ))} 🛑 Avoid using array index as key unless absolutely necessary.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: ✅ Using ternary: {isLoggedIn ? <Logout /> : <Login />} ✅ Using short-circuit: {isVisible && <Sidebar />}
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Fragments let you return multiple elements without adding an extra DOM node. ✅ Example: <> <h1>Title</h1> <p>Description</p> </> 🔍 Equivalent to <React.Fragment> but shorter.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: React uses camelCase syntax and passes functions directly. ✅ Example: <button onClick={handleClick}>Click Me</button>
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: React wraps native browser events in a SyntheticEvent object for cross-browser compatibility. ✅ Example: function handleClick(e) { console.log(e); // SyntheticEvent }
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: ccess value via useState ref Example use case Forms with validation Quick, simple input fields ✅ Controlled: <input value={value} onChange={e => setValue(e.target.value)} /> ✅ Uncontrolled: <input ref={inputRef} />
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Use controlled components and onChange handlers.
✅ Example:
function Form() {
const [name, setName] = useState("");
const handleSubmit = e => {
e.preventDefault();
console.log(name);
};
return (
<form onSubmit={handleSubmit}>
<input value={name} onChange={e => setName(e.target.value)} />
<button type="submit">Submit</button>
</form>
);
}React.js React.js Tutorial · React
Lifting state up means moving state to the nearest common ancestor when multiple
components need to share or modify it.
✅ Example:
function Parent() {
const [value, setValue] = useState("");
return (
<>
<Input value={value} onChange={setValue} />
<Display value={value} />
</>
);
}
function Input({ value, onChange }) {
return <input value={value} onChange={e =>
onChange(e.target.value)} />;
}
function Display({ value }) {
return <p>{value}</p>;
}
React Hooks
React.js React.js Tutorial · React
Answer: Hooks are functions that let you "hook into" React state and lifecycle features in functional components. Before hooks, only class components could use state and lifecycle methods. ✅ Hooks introduced in React 16.8.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
useState lets you add state to functional components.
✅ Syntax:
const [state, setState] = useState(initialValue);
✅ Example:
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}React.js React.js Tutorial · React
useEffect lets you run side effects in functional components (like data fetching,
subscriptions, etc.).
✅ Syntax:
useEffect(() => {
// Side effect
return () => {
// Cleanup
};
}, [dependencies]);
✅ Common use cases:
React.js React.js Tutorial · React
✅ componentDidMount:
useEffect(() => {
console.log("Component mounted");
}, []); // Empty array = run once on mount
✅ componentWillUnmount:
useEffect(() => {
const id = setInterval(() => console.log("tick"), 1000);
return () => {
clearInterval(id); // Cleanup
console.log("Component unmounted");
};
}, []);
React.js React.js Tutorial · React
Feature useEffect useLayoutEffect
When it runs After paint Before paint (after DOM mutation)
Use for Async tasks, data
fetching
Measuring DOM, sync layout
Blocking paint? ❌ No ✅ Yes (can cause jank)
🔍 Use useLayoutEffect only when layout measurement or synchronously modifying
DOM is necessary.
React.js React.js Tutorial · React
useRef creates a mutable reference that persists across renders.
✅ Syntax:
const ref = useRef(initialValue);
✅ Use cases:
✅ Example (DOM access):
const inputRef = useRef();
function focusInput() {
inputRef.current.focus();
}
return <input ref={inputRef} />;
✅ Example (storing previous state):
const prevCount = useRef();
useEffect(() => {
prevCount.current = count;
});
React.js React.js Tutorial · React
useContext lets you consume a context value without using a Context.Consumer.
✅ Example:
const ThemeContext = React.createContext("light");
function App() {
return (
<ThemeContext.Provider value="dark">
<Toolbar />
</ThemeContext.Provider>
);
}
function Toolbar() {
const theme = useContext(ThemeContext);
return <div className={`theme-${theme}`}>Theme is {theme}</div>;
}React.js React.js Tutorial · React
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>;
}React.js React.js Tutorial · React
Answer: void recalculating heavy logic on every render. const filteredList = useMemo(() => { return items.filter(item => item.includes(searchTerm)); }, [items, searchTerm]);
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
useCallback memoizes a function to avoid unnecessary re-creations.
✅ Syntax:
const memoizedCallback = useCallback(() => {
doSomething(a, b);
}, [a, b]);
✅ Use case:
const handleClick = useCallback(() => {
console.log("Clicked!");
}, []);
React.js React.js Tutorial · React
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
React.js React.js Tutorial · React
Redux is a predictable state container for JavaScript apps, often used with React.
✅ Why use Redux?
React.js React.js Tutorial · React
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
Answer: sync support Manual Built-in via middleware DevTools ❌ Limited ✅ Excellent support
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: ✅ Create context: const ThemeContext = React.createContext(); ✅ Provide context: <ThemeContext.Provider value="dark"> <App /> </ThemeContext.Provider> ✅ Consume context: const theme = useContext(ThemeContext);
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Middleware are functions that sit between dispatching an action and reaching the
reducer.
✅ Common uses:
✅ Examples:
✅ Example (redux-logger):
const logger = store => next => action => {
console.log('dispatching', action);
return next(action);
};
React.js React.js Tutorial · React
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
Redux Toolkit (RTK) is the official, recommended way to write Redux logic.
✅ RTK Benefits:
✅ Example:
const counterSlice = createSlice({
name: 'counter',
initialState: 0,
reducers: {
increment: (state) => state + 1,
},
});
export const { increment } = counterSlice.actions;React.js React.js Tutorial · React
✅ Using middleware, such as:
✅ Example with thunk:
const fetchData = () => async (dispatch) => {
const response = await fetch('/data');
const data = await response.json();
dispatch({ type: 'SET_DATA', payload: data });
};
React.js React.js Tutorial · React
Selectors are functions that read and return data from the store, often with memoization.
✅ Purpose:
✅ 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
React.js React.js Tutorial · React
Answer: pplications (SPA). Declarative routing: Allows you to define routes using JSX. Dynamic routing: Routes can be dynamically rendered based on the state, props, or URL.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
You can implement routing in React using React Router. Here's how:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
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
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>;
}React.js React.js Tutorial · React
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.
React.js React.js Tutorial · React
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>
);
}React.js React.js Tutorial · React
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.
React.js React.js Tutorial · React
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
React.js React.js Tutorial · React
Common causes of performance issues include:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
React.memo is a higher-order component that memoizes functional components. It only
re-renders the component if its props have changed.
const MyComponent = React.memo(function MyComponent({ name }) {
return <div>{name}</div>;
});
// MyComponent will only re-render if the `name` prop changes
React.js React.js Tutorial · React
useMemo:
useMemo is a hook that memoizes the result of an expensive function call and only
recomputes the value when one of the dependencies changes.
every render.
Example:
const expensiveValue = useMemo(() => computeExpensiveValue(a, b),
[a, b]);
// expensiveValue will only recompute when `a` or `b` changes
useCallback:
useCallback is used to memoize a function so it doesn’t get recreated on every render.
components (important when using React.memo or PureComponent).
Example:
const handleClick = useCallback(() => {
// handle the click event
}, [dependencies]); // Recreate the function only when dependencies
change
React.js React.js Tutorial · React
Answer: Code splitting is the practice of breaking up the bundle into smaller chunks so that only the required code is loaded when needed, improving initial load performance. How to Implement:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Lazy loading is a design pattern where resources (like components) are loaded only when
they are needed (e.g., when they enter the viewport or the user navigates to the route).
In React, lazy loading is typically implemented using React.lazy and Suspense.
Example:
import { Suspense } from 'react';
const HeavyComponent = React.lazy(() => import('./HeavyComponent'));
function App() {
return (
<Suspense fallback={<div>Loading...</div>}>
<HeavyComponent />
</Suspense>
);
}
This ensures that the heavy component is only loaded when the app actually needs it.
React.js React.js Tutorial · React
shouldComponentUpdate is a lifecycle method in class components that determines
whether a component should re-render. By default, a component re-renders when state or
props change, but shouldComponentUpdate allows you to optimize this behavior.
Example:
class MyComponent extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
// Prevent re-render if props haven't changed
return nextProps.name !== this.props.name;
}
render() {
return <div>{this.props.name}</div>;
}
}React.js React.js Tutorial · React
Answer: Rendering large lists can cause performance issues if each item re-renders unnecessarily. Here are some strategies:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Pure Component is a React class component that automatically implements
shouldComponentUpdate with a shallow prop and state comparison.
props and state.
Example:
class MyComponent extends React.PureComponent {
render() {
return <div>{this.props.name}</div>;
}
}
Pure components are a good choice when you know that your component only depends on
props and state and you want to avoid unnecessary updates.
React.js React.js Tutorial · React
Virtualization is a technique where only the items that are visible in the viewport are
rendered, while the others are not rendered until they come into view. This significantly
reduces the number of DOM nodes and boosts performance when rendering large lists.
Popular libraries for virtualization in React include:
Example with react-window:
import { FixedSizeList as List } from 'react-window';
function MyList({ items }) {
return (
<List
height={400}
itemCount={items.length}
itemSize={35}
width={300}
{({ index, style }) => (
<div style={style}>{items[index]}</div>
)}
</List>
);
}
Only the visible items will be rendered, and as the user scrolls, new items will be loaded
dynamically.
React.js React.js Tutorial · React
Debugging performance issues can be done using several tools and strategies:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: You test React components by writing unit tests that simulate rendering, interaction, and lifecycle behavior. Key Steps:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Jest is a JavaScript testing framework created by Facebook, commonly used for testing
React applications. It comes with:
How to use Jest with React:
Install Jest:
npm install --save-dev jest
React.js React.js Tutorial · React
ccessibility
Shallow rendering, component
state, and props
Testing Approach Encourages testing DOM
behavior and accessibility
Encourages testing component
internals and methods
Integration with
React
Built with React’s rendering
behavior in mind
Requires enzyme adapter for
different React versions
Recommendation More modern, encourages
better testing practices
Still used, but React Testing
Library is more popular
Key difference:
behavior), similar to how a user interacts with the app.
methods).
React.js React.js Tutorial · React
Answer: unit test checks a small unit of functionality, such as a React component. Here’s how you can write a unit test:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
To test component interactions like button clicks, form submissions, or other events, you
can use fireEvent or user-event (for more realistic user interactions).
Example using fireEvent:
import { render, screen, fireEvent } from '@testing-library/react';
import MyComponent from './MyComponent';
test('button click changes text', () => {
render(<MyComponent />);
const button = screen.getByText('Click me');
fireEvent.click(button);
expect(screen.getByText('You clicked!')).toBeInTheDocument();
});
Example using user-event (better for simulating real user interactions):
npm install --save-dev @testing-library/user-event
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MyComponent from './MyComponent';
test('button click changes text', () => {
render(<MyComponent />);
const button = screen.getByText('Click me');
userEvent.click(button);
expect(screen.getByText('You clicked!')).toBeInTheDocument();
});
user-event is better because it simulates real user actions like clicks, typing, and more.
React.js React.js Tutorial · React
Answer: To mock API calls in tests, you can use jest.mock() to mock functions or API calls. Mocking fetch or axios: Mock fetch: global.fetch = jest.fn(() => Promise.resolve({ json: () => Promise.resolve({ data: 'mock data' }), }) );
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: wait waitFor(() => screen.getByText('Loaded Data')); expect(screen.getByText('Loaded Data')).toBeInTheDocument(); }); In this case, waitFor() waits until the expected element appears in the DOM after an sync operation completes.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Snapshot testing is a way of testing a component’s rendered output by saving it to a
snapshot file and comparing it with future renders. This helps detect any unintended
changes in the UI.
How to write snapshot tests:
Run Jest with snapshot testing:
npm test -- --updateSnapshot
React.js React.js Tutorial · React
Higher-Order Component (HOC) is a function that takes a component and returns a
new component with additional props or behavior.
components with common functionality (e.g., authentication, data fetching, etc.).
before rendering the component.
Example:
function withLoading(Component) {
return function WithLoading(props) {
if (props.isLoading) {
return <div>Loading...</div>;
}
return <Component {...props} />;
};
}
const MyComponent = ({ data }) => <div>{data}</div>;
const MyComponentWithLoading = withLoading(MyComponent);
In this example, withLoading is a higher-order component that adds loading state to
MyComponent.
React.js React.js Tutorial · React
llowing more dynamic behavior and custom rendering.
define how the output is rendered.
Example:
class MouseTracker extends React.Component {
state = { x: 0, y: 0 };
handleMouseMove = (event) => {
this.setState({
x: event.clientX,
y: event.clientY,
});
};
render() {
return (
<div onMouseMove={this.handleMouseMove}>
{this.props.render(this.state)}
</div>
);
}
}
const App = () => (
<MouseTracker render={({ x, y }) => (
<h1>The mouse position is ({x}, {y})</h1>
)} />
);
In this example, MouseTracker uses the render prop pattern to allow the parent
component to decide how to render the mouse position data.
React.js React.js Tutorial · React
Portal provides a way to render children into a different part of the DOM outside of the
parent component’s DOM hierarchy. This is particularly useful for scenarios like modals,
tooltips, or popups that need to visually break out of their parent component but still maintain
their React component state.
parent, without losing the React component context (e.g., for modals, overlays, etc.).
Example:
import React from 'react';
import ReactDOM from 'react-dom';
function Modal() {
return ReactDOM.createPortal(
<div className="modal">This is a modal</div>,
document.getElementById('modal-root') // Renders outside the
normal DOM tree
);
}
export default Modal;
In this case, the modal is rendered inside a specific part of the DOM (modal-root) even
though it is a child of the Modal component.
React.js React.js Tutorial · React
Reconciliation is the process by which React updates the DOM efficiently when a
component's state or props change. React uses a virtual DOM to compare the new virtual
DOM tree with the previous one and determines the minimal set of changes required to
update the actual DOM.
Key Concepts:
the differences (diffs) and apply the smallest set of changes.
Reconciliation Flow:
React.js React.js Tutorial · React
React Fiber is a complete rewrite of React's reconciliation algorithm. It is designed to
improve the rendering performance and make React more responsive and capable of
handling asynchronous rendering.
Key Features:
can pause and resume work, improving responsiveness.
vs. background updates).
responsive.
React.js React.js Tutorial · React
n Error Boundary is a React component that catches JavaScript errors in its child
components, logs those errors, and displays a fallback UI. This prevents the entire app from
crashing when an error occurs in a part of the component tree.
Usage:
React.js React.js Tutorial · React
nd helps with SEO. SSR Process:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Static Site Generation (SSG) is a technique where HTML pages are generated at build
time. Unlike SSR, SSG pre-renders all pages during the build process, which results in
faster load times.
Example with Next.js (SSG):
import React from 'react';
export async function getStaticProps() {
const data = await fetchDataFromAPI();
return { props: { data } };
}
function Page({ data }) {
return <div>{data}</div>;
}
export default Page;
Here, getStaticProps is a Next.js function that fetches data during build time. The page
is pre-rendered and served as static HTML.
React.js React.js Tutorial · React
Hydration refers to the process where React takes over the static HTML rendered by the
server and attaches event listeners and restores interactivity. This happens once the
JavaScript bundle is loaded on the client.
This process allows the page to load quickly (thanks to the server-rendered HTML) and then
become fully interactive once React takes over.
React Ecosystem & Tools
React.js React.js Tutorial · React
nd developer experience.
Why use Next.js?
better SEO and faster initial load.
performance.
page.
Example:
npx create-next-app my-next-app
In this setup, the app can be SSR or SSG-enabled, providing better performance and SEO
out of the box.
React.js React.js Tutorial · React
Create React App (CRA) is a boilerplate tool to set up a modern React app without
configuring build tools like Webpack, Babel, etc. It’s designed to help you focus on writing
code instead of spending time configuring tools.
Features:
optimization, etc.
How to Use CRA:
npx create-react-app my-app
cd my-app
npm start
With CRA, you don’t have to manually configure Webpack or Babel. It gives you everything
you need to start building React applications right away.
React.js React.js Tutorial · React
Some common build tools for React are:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: There are several ways to handle CSS in React applications, and each comes with its own pros and cons.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: CSS-in-JS libraries allow you to write CSS styles directly inside JavaScript files, enabling better component encapsulation and dynamic styling. Popular libraries include:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: ge: PropTypes.number.isRequired, }; In this example, PropTypes.string.isRequired ensures that the name prop is a string nd is required. If it’s not passed or is of the wrong type, React will display a warning in the console.
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: Internationalization (i18n) in React can be handled using libraries that help manage translations, time formats, and currency formatting. The most common libraries are:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Answer: uthentication in React apps is typically done using tokens (JWTs) and local storage to persist user sessions. Common Steps:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
React Native is a framework for building native mobile applications (iOS and Android)
using React and JavaScript. While React is for web development, React Native allows you
to create mobile apps with a similar paradigm but using native components (e.g., <View>
instead of <div>).
Key Differences:
with mobile devices (camera, geolocation, etc.).
Example in React Native:
import { Text, View } from 'react-native';
function App() {
return (
<View>
<Text>Hello, React Native!</Text>
</View>
);
}
In React Native, the components map to native UI elements, such as <Text> for text,
<View> for containers, and <Button> for buttons.
React.js React.js Tutorial · React
Managing forms in React can be tedious, but libraries like Formik and React Hook Form
simplify form handling by managing state, validation, and submission.
Formik:
Example with Formik:
import { Formik, Field, Form } from 'formik';
function MyForm() {
return (
<Formik
initialValues={{ name: '', email: '' }}
onSubmit={(values) => console.log(values)}
<Form>
<Field name="name" />
<Field name="email" />
<button type="submit">Submit</button>
</Form>
</Formik>
);
}
React Hook Form:
Example with React Hook Form:
import { useForm } from 'react-hook-form';
function MyForm() {
const { register, handleSubmit } = useForm();
const onSubmit = (data) => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('name')} />
<input {...register('email')} />
<button type="submit">Submit</button>
</form>
);
}
Both libraries significantly reduce boilerplate and handle common issues like validation and
form state management.
Hooks Deep Dive
React.js React.js Tutorial · React
Infinite loops in useEffect occur when the effect continually triggers itself because the
dependency array includes values that change as a result of the effect itself.
Common cause:
If a value inside useEffect is being updated, and it's in the dependency array, React will
keep rerunning the effect.
How to avoid:
Example:
useEffect(() => {
// Perform API call or other side effects
fetchData();
}, []); // No dependencies, effect runs only once
If the dependency list has state values or props that change inside the effect, React will
rerun it every time those values change. Be mindful of that!
React.js React.js Tutorial · React
Custom hooks are a powerful way to share logic between components in a reusable and
encapsulated way. A custom hook is simply a JavaScript function that uses React hooks
(like useState, useEffect, etc.).
Example of a custom hook:
// useLocalStorage.js
import { useState } from 'react';
function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(() => {
const item = localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
});
const setValue = (value) => {
setStoredValue(value);
localStorage.setItem(key, JSON.stringify(value));
};
return [storedValue, setValue];
}
export default useLocalStorage;
You can then use this custom hook in any component:
import useLocalStorage from './useLocalStorage';
function App() {
const [name, setName] = useLocalStorage('name', 'John');
return (
<div>
<input
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter your name"
/>
</div>
);
}
Custom hooks allow for reusable logic (like managing form state, fetching data, etc.) and
encapsulation of behavior in a way that doesn't require repeated code.
React.js React.js Tutorial · React
In class components, the lifecycle is managed using methods like componentDidMount,
componentDidUpdate, and componentWillUnmount. With hooks, these are replaced
with useEffect, which can mimic any lifecycle behavior.
Lifecycle Mapping:
Example:
useEffect(() => {
// Equivalent to componentDidMount and componentDidUpdate
console.log("Component mounted or updated");
return () => {
// Equivalent to componentWillUnmount
console.log("Cleanup before component unmount");
};
}, [dependencies]); // Will run on mount and update based on
dependencies
React.js React.js Tutorial · React
React keys help React identify which items in a list are changed, added, or removed. Keys
provide a stable identity for each element, allowing React to optimize re-renders.
changes, which can be inefficient.
Example:
const items = ['apple', 'banana', 'cherry'];
return (
<ul>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
);
the list can change order or content dynamically.
React.js React.js Tutorial · React
Handling errors in React is done using Error Boundaries. They are React components
that catch JavaScript errors anywhere in their child component tree and log those errors or
display a fallback UI.
Example of Error Boundary:
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
return { hasError: true }; // Update state to trigger fallback
UI
}
componentDidCatch(error, info) {
console.error(error, info);
}
render() {
if (this.state.hasError) {
return <h1>Something went wrong!</h1>;
}
return this.props.children;
}
}
You wrap your components inside ErrorBoundary to catch and handle errors gracefully.
React.js React.js Tutorial · React
To optimize React apps for SEO (Search Engine Optimization):
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
Reconciliation is the process React uses to update the UI efficiently when state or props
change. React compares the old virtual DOM with the new virtual DOM and calculates the
minimal set of changes required to update the real DOM. This makes React apps fast and
efficient.
Why important:
re-renders.
DOM updates.
React.js React.js Tutorial · React
Answer: new virtual DOM, compares it to the previous version, and calculates the most efficient way to update the actual DOM. Steps:
In a production React.js application, teams apply this when handling user-facing features or integration boundaries. For example, you might use it during a sprint where reliability and observability matter—logging metrics, validating edge cases, and documenting the decision in an ADR so future developers understand why the approach was chosen.
Tip: Practice aloud on Toolliyo mock interview or the Interview Q&A section before your real interview.
React.js React.js Tutorial · React
ngular:
form handling, and more.
Vue:
React.js React.js Tutorial · React
JSX transpilation refers to the process of converting JSX syntax (JavaScript XML) into
regular JavaScript. Since browsers don't understand JSX directly, tools like Babel transpile
JSX into valid JavaScript that browsers can execute.
Example:
const element = <h1>Hello, world!</h1>;
Babel transpiles the JSX into:
const element = React.createElement('h1', null, 'Hello, world!');React.js React.js Tutorial · React
You can use libraries like react-dnd or react-beautiful-dnd for drag-and-drop functionality.
Example with react-beautiful-dnd:
npm install react-beautiful-dnd
import { DragDropContext, Droppable, Draggable } from
'react-beautiful-dnd';
function App() {
const items = ['item1', 'item2', 'item3'];
return (
<DragDropContext onDragEnd={() => {}}>
<Droppable droppableId="droppable">
{(provided) => (
<ul ref={provided.innerRef} {...provided.droppableProps}>
{items.map((item, index) => (
<Draggable key={item} draggableId={item}
index={index}>
{(provided) => (
<li
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
{item}
</li>
)}
</Draggable>
))}
{provided.placeholder}
</ul>
)}
</Droppable>
</DragDropContext>
);
}React.js React.js Tutorial · React
Concurrent Mode is an experimental feature in React that enables the rendering process to
be interruptible. It allows React to work on multiple tasks at once, making apps feel more
responsive by prioritizing higher-priority updates (like animations or user input) over
lower-priority ones.
React.js React.js Tutorial · React
React.lazy enables you to dynamically import components only when they are needed,
enabling code splitting and lazy loading.
const LazyComponent = React.lazy(() => import('./LazyComponent'));
function App() {
return (
<React.Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</React.Suspense>
);
}
Suspense is a wrapper around lazy-loaded components that shows a loading fallback
while the component is being loaded.