ReactJS Interview Questions Complete
ReactJS Interview Questions Complete
1. What is ReactJS?
ReactJS is a JavaScript library developed by Facebook for building user interfaces, especially
single-page applications. It helps create fast and interactive UIs using reusable components.
- Class Component: Uses ES6 classes, can use lifecycle methods, and state is managed using
`this.state`.
- Functional Component: A simpler syntax using functions; can use Hooks for state and side effects.
4. What is JSX?
JSX (JavaScript XML) allows you to write HTML-like syntax in JavaScript files. It makes the code
Props (short for "properties") are read-only inputs passed from a parent to a child component. They
help make components reusable.
State is a built-in object used to contain data or information about the component. It can be changed
cd my-app
npm start
The Virtual DOM is a lightweight copy of the actual DOM. React updates the virtual DOM first,
compares it with the previous version (diffing), and then updates only the changed parts in the real
DOM.
In class components, render() returns the JSX that should be rendered on the screen.
- componentDidMount(): Called once after the component is added to the DOM. Used for API calls
or DOM manipulations.
- componentWillUnmount(): Called just before the component is removed. Used for cleanup (e.g.,
Hooks are functions introduced in React 16.8 that let you use state and lifecycle features in
functional components.
2. What is useState()?
Example:
3. What is useEffect()?
useEffect lets you perform side effects (like data fetching, setting timers) in functional components.
Example:
useEffect(() => {
By using state to store the form values and onChange handlers to update them.
Example:
Conditional Rendering
Example:
{isLoggedIn ? <Logout /> : <Login />}
Example:
Keys help React identify which items have changed, are added, or removed, improving performance
during re-renders.