What is React JS?
React JS is a front-end JavaScript library used to build user interfaces, especially for single-page applications. It allows developers to create reusable UI components.
What are the features of React?
- Virtual DOM
- JSX (JavaScript XML)
- Component-based architecture
- One-way data binding
- Fast rendering
- Reusable components
What is JSX?
JSX stands for JavaScript XML. It allows you to write HTML-like code inside JavaScript. It helps make code more readable and easier to write React components.
const element = Hello, World!
;
What is the difference between a class component and a functional component?
| Class Component |
Functional Component |
| Uses ES6 classes |
Uses plain JS functions |
| Supports state and lifecycle methods |
Uses hooks to manage state |
| More complex |
More concise |
What is a component in React?
A component is a reusable piece of code that represents a part of the UI. React has two types of components:
- Functional Components
- Class Components
What are props in React?
Props (short for properties) are used to pass data from one component to another. They are read-only and help create dynamic content.
function Welcome(props) {
return Hello, {props.name}
;
}
What is state in React?
State is an object used to store component-specific data that can change over time. When the state changes, React re-renders the component.
What is the use of useState hook?
useState is a React hook that lets you add state to functional components.
const [count, setCount] = useState(0);
What is the Virtual DOM?
Virtual DOM is a lightweight copy of the real DOM. React uses it to update only the changed parts of the DOM, improving performance.
What is the useEffect hook in React?
useEffect allows you to perform side effects like data fetching, subscriptions, or manually changing the DOM from within a functional component.
useEffect(() => {
console.log("Component mounted");
}, []);
What are React lifecycle methods?
These are special methods in class components that are automatically invoked at different stages of a component’s life:
- componentDidMount()
- componentDidUpdate()
- componentWillUnmount()
How does routing work in React?
React uses React Router for client-side routing. It allows developers to navigate between components/pages without reloading the page.
import { BrowserRouter as Router, Route } from "react-router-dom";
How do you pass data between components in React?
- From parent to child: via props
- From child to parent: via callback functions
- Between unrelated components: via context API or state management libraries
How do you handle forms in React?
You can use controlled components with state to handle form input:
What are Higher-Order Components (HOCs)? How do you create one?
- A Higher-Order Component is a function that takes a component and returns a new component. It’s used for reusing component logic.
- It doesn't modify the original component; instead, it wraps it.
What is React’s Reconciliation process?
- Reconciliation is React’s process of diffing the virtual DOM tree, comparing the new virtual DOM with the previous one, and figuring out the minimal set of changes needed to update the real DOM.
- React uses heuristics (like keys on lists) to optimise this.
- The algorithm helps in performance by reducing direct DOM operations.
What are React Portals and when might you use them?
- Portals provide a way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.
- Syntax: ReactDOM.createPortal(child, containerNode).
Explain the difference between controlled and uncontrolled components in forms.
- Controlled component: Form data is handled by React component state. Every change (e.g. user typing) triggers state update and re-render. React is the single source of truth.
- Uncontrolled component: Form data is handled by the DOM itself. You use refs to access input values. Less code for simple usage, but less control.
What is Concurrent Mode / Concurrent Features in React? What problems does it solve?
- Concurrent mode (also called concurrent features) is a set of React capabilities that allows React to prepare multiple versions of the UI at the same time. It helps React manage interruptible tasks, smoothing user experience.
- Solves problems like UI stutters, long blocking tasks, rendering large trees, slow network, etc.
- It gives React ability to pause, abort, or delay work as needed to keep the interface responsive.
- Examples: Suspense for Data Fetching, transitions (like startTransition()), etc.
What is React Suspense & how does it relate to lazy loading components or data?
- Suspense is a React feature that lets you “wait” for something before rendering, showing a fallback UI in the meantime.
- Commonly used with React.lazy() to lazy-load components.
- Also being extended for data fetching (though depending on version and libraries) so components can “suspend” while waiting for data.
What are React Hooks rules? Name a few common hooks other than useState and useEffect.
Rules:
- Only call hooks at the top level (don’t call inside loops, conditionals, nested functions).
- Only call hooks from React functions (functional components or custom hooks), not from regular JS functions.
Common other hooks:
- useContext – to access React Context in functional component.
- useMemo – memoize expensive computations.
- useCallback – memoize callback functions.
- useRef – maintain mutable values that persist across renders, or DOM refs.
- useReducer – alternative to useState when state logic is complex.
What is Context API in React? When should you use it, and what are its limitations?
- The Context API provides a way to pass data through the component tree without having to pass props down manually at every level.
- Use cases: theme, language settings, user authentication info, etc.
Limitations:
- Context can cause re-renders of all consuming components when the value changes (unless optimised), which can affect performance.
- Overuse for everything can make components less reusable or harder to understand.
- Doesn’t replace state management entirely in larger apps; sometimes external libraries (Redux, MobX, Zustand etc.) are useful for more complex state.
How does React optimize performance? Mention a few techniques.
Key techniques include:
- Using keys in lists so that React can correctly track items and avoid unnecessary re-renders.
- Memoization: React.memo for functional components, shouldComponentUpdate for class components.
- useMemo & useCallback hooks to avoid expensive recalculations or recreating functions unnecessarily.
- Lazy loading components (React.lazy) so that portions of UI are loaded only when needed.
- Code splitting (dynamic imports).
- Using virtualization for large lists (e.g. react-window, react-virtualized).
- Avoiding inline functions or object literals in render where possible, or using stable references.
Explain how server-side rendering (SSR) works with React, and what advantages and trade-offs it has.
- SSR means rendering React components on the server into HTML, then sending them to the client, where React hydrates (takes over) the static HTML and attaches event handlers etc.
Advantages:
- Better performance for first render, especially on slow networks or devices.
- Improved SEO (since bots / crawlers see rendered content).
- Faster Time to First Paint / Time to Interactive.
Trade-offs:
- More complex build & deployment process.
- Higher server load (since rendering happens on server CPU).
- Need to ensure hydration safety (client side matches server side HTML) to avoid mismatches.
- Sometimes state/data loading synchronization between server and client must be handled carefully.
What is the difference between React and ReactDOM?
- React is the core library for building components, managing state, and the virtual DOM.
- ReactDOM handles rendering React components into the actual DOM of the browser.
What is JSX and why is it used?
- JSX is a syntax extension of JavaScript that looks like HTML and is used to describe UI components.
- React converts JSX to React.createElement() calls behind the scenes.
What are props in React?
- RProps (short for properties) are read-only inputs passed from a parent component to a child component.
- Props allow components to be reusable and dynamic.
What is the difference between state and props?
- Props are passed from parent to child and are read-only.
- State is managed within the component and can change over time with setState (class) or useState (functional).
Can you use multiple states in a functional component?
- Yes, using multiple useState hooks:
What is the virtual DOM in React?
- Virtual DOM is an in-memory lightweight representation of the real DOM.
- React uses it to determine the minimal changes needed when the UI updates (diffing algorithm) to optimize performance.
What is the difference between class and functional components?
- Class components can use lifecycle methods and state (before hooks).
- Functional components are simpler, do not have this, and now can use state and lifecycle via hooks.
What is useEffect hook and common use-cases?
- useEffect runs side effects in functional components: API calls, subscriptions, timers, etc.
- By default, it runs after every render; dependencies array can control when it runs.
- Understand the basics of JavaScript and ES6
- Practice with small projects (To-do app, calculator, etc.)
- Be confident in explaining React hooks and component lifecycle
- Keep updated with the latest React features and versions
If you are looking for other courses checkout here -
Data Analytics Training |
HR Training |
SEO Training