Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Answer: uthentication in React apps is typically done using tokens (JWTs) and local storage to persist user sessions. Common Steps: What interviewers expect A clear definition tied to React in React.js projects Trade-off…
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: Provides an easy way to manage form state, validation, a…
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…
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 cus…
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. Lif…
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. Important: Keys should be unique for each sibli…
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 Bound…
To optimize React apps for SEO (Search Engine Optimization): What interviewers expect A clear definition tied to React in React.js projects Trade-offs (performance, maintainability, security, cost) When you would and wou…
Answer: new virtual DOM, compares it to the previous version, and calculates the most efficient way to update the actual DOM. Steps: What interviewers expect A clear definition tied to React in React.js projects Trade-of…
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-…
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.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
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
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
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
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.