Top 100 React Interview Q&A ?
Top 100 React Interview Q&A ?
Interview Q&A
Made by Want More
1. What is React?
JSX is a syntax extension used in React that allows you to write HTML-like
code within JavaScript. It provides a convenient way to define the
structure and appearance of React components.
Functional components are simpler and easier to read and test compared
to class components. They don't have their own state or lifecycle methods.
Class components, on the other hand, can manage their own state and
have access to lifecycle methods such as componentDidMount() and
componentDidUpdate().
Props (short for properties) are used to pass data from a parent
component to a child component. Props are read-only and cannot be
modified by the child component. They are passed as attributes to the
child component in JSX.
Keys are used in React lists to give each item a unique identifier. They help
React identify which items have changed, been added, or been removed
in a list, improving performance and avoiding unnecessary re-rendering of
components.
Refs are used in React to get direct access to a DOM element or a React
component instance. They provide a way to interact with the underlying
DOM or component imperatively, outside of the typical React data flow.
React Hooks are functions introduced in React 16.8 that allow you to use
state and other React features in functional components. Hooks provide a
way to use local component state, lifecycle methods, and other React
features without writing a class.
The useMemo() Hook is a built-in Hook in React that memoizes the result
of a computation and returns the cached result when the dependencies
haven't changed. It helps in optimizing performance by avoiding
unnecessary expensive calculations.
24. What is the useReducer() Hook used for?
React Fragments are a feature in React that allows you to group a list of
children without adding extra nodes to the DOM. They are useful when
you need to return multiple elements from a component's render()
method, but they don't need a parent container element.
The useRef() Hook is a built-in Hook in React that provides a way to create
a mutable reference that persists across re-renders of a component. It can
be used to access DOM elements or store mutable values that won't
trigger re-renders.
React context provides a way to pass data through the component tree
without having to pass props manually at every level. It allows you to
create a global state accessible to all components within a context
provider.
The key prop is used in React lists to give each item a unique identifier. It
helps React identify which items have changed, been added, or been
removed in a list, improving performance and avoiding unnecessary re-
rendering of components.
The React Context API provides a way to share data across a component
tree without manually passing props down through every level. It is useful
when you have data that needs to be accessed by multiple components at
different levels in the component hierarchy.
The React DevTools Profiler is a tool used for profiling and optimizing the
performance of React applications. It allows you to analyze and measure
component render times and interactions to identify performance
bottlenecks and optimize your application.
To handle form submissions in React, you can use the onSubmit event
handler on the form element. You can prevent the default form
submission behavior using event.preventDefault() and then access the
form data from the event object to perform further processing or submit
data to a server.