React
React
PM Claude
⚛ React Interview
Questions
50+ Essential Questions with Answers & Code Examples
// JSX
const element = <h1>Hello, {name}!</h1>;
@Zeeshan
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 1/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
// Compiled JavaScript
const element = React.createElement('h1', null, 'Hello, ', name, '!');
Component-based
architecture Virtual DOM for
performance JSX syntax
One-way data binding
Reusable components
Strong ecosystem and community
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 2/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
// Element
const element = <h1>Hello</h1>;
// Component
function Welcome() {
return <h1>Hello</h1>;
}
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 3/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
// Functional Component
function Welcome(props) {
return <h1>Hello, {props.name}!</h1>;
}
// Class Component
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}!</h1>;
}
}
// Parent component
function App() {
return <UserCard name="John" age={25} />;
}
// Child component
function UserCard(props) {
return (
<div>
<h2>{props.name}</h2>
<p>Age: {props.age}</p>
</div>
);
}
Props destructuring extracts properties from the props object for cleaner code.
// Without destructuring
function UserCard(props) {
return <h1>{props.name}</h1>;
}
// With destructuring
function UserCard({ name, age })
{ return (
<div>
<h1>{name}</h1>
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 4/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
<p>Age: {age}</p>
</div>
);
}
Default props provide fallback values when props are not passed.
// Functional component
function Button({ text = "Click me", type = "button" })
{ return <button type={type}>{text}</button>;
}
// Class component
class Button extends React.Component
{ static defaultProps = {
text: "Click me",
type: "button"
};
render() {
return <button type={this.props.type}>{this.props.text}</button>;
}
}
function App() {
const user = { name: "John" };
return (
<UserContext.Provider value={user}>
<Header />
</UserContext.Provider>
);
}
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 5/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
// Usage
<Card>
<h2>Title</h2>
<p>Content here</p>
</Card>
UserCard.propTypes = {
name: PropTypes.string.isRequired,
age: PropTypes.number,
email: PropTypes.string
};
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 6/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
render() {
return <h1>Count: {this.state.count}</h1>;
}
}
function App() {
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 7/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM const [temperature, setTemperature]
Claude = useState(0);
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 8/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
return (
<div>
<TemperatureInput
value={temperature}
onChange={setTemperature}
/>
<BoilingVerdict celsius={temperature} />
</div>
);
}
// Better approach
this.setState(prevState => ({
count: prevState.count + 1
}));
// Array state
const [items, setItems] = useState(['apple', 'banana']);
// Add item
setItems([...items, 'orange']);
// Remove item
setItems(items.filter(item => item !== 'apple'));
// Object state
const [user, setUser] = useState({ name: 'John', age: 25 });
// Update property
setUser({ ...user, age: 26 });
setUser(prev => ({ ...prev, age: prev.age + 1 }));
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 9/14
573556b1ffab
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
// Updating
componentDidUpdate(prevProps, prevState)
{ console.log('Component updated');
}
// Unmounting
componentWillUnmount() {
console.log('Component will unmount');
}
render() {
return <div>Hello</div>;
}
}
function UserList() {
const [users, setUsers] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchUsers()
{ try {
const response = await fetch('/api/users'); const
userData = await response.json();
setUsers(userData);
} catch (error)
{ console.error('Error:',
error);
} finally {
setLoading(false);
}
}
fetchUsers();
}, []);
useEffect(() => {
// Subscribe
const subscription = API.subscribe(handleData); const
timer = setInterval(fetchData, 1000);
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 11/
573556b1ffab 14
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
The dependency array controls when the effect runs.
useEffect(() =>
{ localStorage.setItem('theme',
theme);
}, [theme]);
27. componentDidMount
vs useEffect comparison? Medium
// Class component
class UserProfile extends React.Component
{ componentDidMount() {
this.fetchUser();
}
componentWillUnmount() {
this.cleanup();
}
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 12/
573556b1ffab 14
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
Hooks are functions that let you use state and lifecycle features in
functional components. They start with "use".
function MyComponent() {
const [count, setCount] = useState(0); // State hook
useEffect(() => {
document.title = `Count: ${count}`;
}, [count]); // Effect hook
1.Only call hooks at the top level (not inside loops, conditions,
or nested functions)
2.Only call hooks from React function components or custom hooks
// ✗ Wrong
function BadComponent()
{ if (someCondition) {
const [state, setState] = useState(0); // Don't do this!
}
// ✓ Correct
function GoodComponent() {
const [state, setState] = useState(0);
const [name, setName] = useState('');
useEffect(() => {
// Effect logic here
}, [state]);
}
// Basic usage
const [count, setCount] = useState(0);
// With object
const [user, setUser] = useState({ name: '', email: '' });
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 13/
573556b1ffab 14
8/20/25, 12:26 React Interview Questions PDF -
PM Claude
const [expensiveValue, setExpensiveValue] = useState(() =>
{ return computeExpensiveValue();
});
return (
<form>
<input
value={email}
onChange={e => setEmail(e.target.value)}
/>
<input
type="password"
https://claude.ai/chat/73c511ed-1b35-4f79-ac5f- 14/
573556b1ffab 14