React Js
React Js
React.js
Q: What is the virtual DOM, and how does React use it?
A: The virtual DOM is a lightweight JavaScript object representing the real DOM. React updates the
virtual DOM first, calculates the differences, and then efficiently updates only the changed parts in the
real DOM.
A: React components go through mounting, updating, and unmounting phases. With class
A: Controlled components use React state to manage input values, while uncontrolled components
A: useState manages local state in functional components, and useEffect performs side effects like
A: It manages form state efficiently, provides validation, and reduces re-renders compared to
controlled inputs.
Redux & Context API
A: Redux is better for large apps with complex state logic, while Context API is ideal for passing down
A: Actions describe changes, reducers handle the logic, and the store holds the global state tree.
A: Middleware like redux-thunk or redux-saga intercepts actions to handle async logic before they
reach reducers.
React Router
A: Use <BrowserRouter> and <Routes> with <Route path='/example' element={<Component />} />.
A: It retrieves dynamic parts of the URL, like ID or slug, from the route parameters.
A: Add a Route with path='*' to catch undefined routes and show a NotFound component.
Q: What are the advantages of using Vite over Create React App (CRA)?
A: Vite offers faster dev server startup, instant HMR, and smaller production builds using ESBuild and
Rollup.
A: Use try-catch blocks and state variables like isLoading and error to manage UI feedback.
JavaScript
A: == compares values after type conversion; === compares both type and value without conversion.
A: A closure is a function that remembers variables from its outer scope even after the outer function
has returned.
A: Variables and functions are 'hoisted' to the top of their scope, but only declarations are hoisted, not
initializations.
A: Use responsive prefixes like md:, lg:, xl: to apply styles based on screen size.
A: Utility classes like p-4, m-2, bg-blue-500 apply one style each and are composed together for fast
styling.
A: Use className with ternary logic or libraries like clsx to toggle classes conditionally.
A: Tags like <header>, <main>, <section> add meaning to content, improving accessibility and SEO.
A: Flexbox is for one-dimensional layout (row or column), while Grid handles two-dimensional layout
responsive design.
A: git fetch downloads updates without merging, while git pull does both fetch and merge.
A: Manually edit the conflicted file, remove conflict markers, then stage and commit the resolved
version.
A: A pull request is a GitHub feature to review and merge code. You create one after pushing your
1. What is ReactJS?
ReactJS is a JavaScript library used to build reusable components for the view layer in the MVC
architecture. It is used to build the Single Page Application (SPA) due to its component-based
architecture, efficient re-rendering with the Virtual DOM, and ability to manage dynamic content
Virtual DOM: React uses a virtual DOM to efficiently update and render components, ensuring
Hooks: React Hooks allow functional components to manage state and side effects, making
Server-Side Rendering (SSR): React can be used for server-side rendering, where HTML
content is generated on the server and sent to the client. This improves the app's performance,
React Router: React Router enables navigation in a React application. It allows you to define
The latest stable version of React is v19.1.0, released on March 28, 2025 . This version builds upon
the major updates introduced in React v19.0.0, which was officially released on December 5, 2024.
application into three main logical components: Model, View, and Controller. Each architectural
component is built to handle specific development aspects of an application. It isolates the business,
JSX: It stands for JavaScript and XML and allows you to write HTML in React.
Props and State: props are like function parameters and State is similar to variables.
Virtual DOM: It is a lightweight copy of the actual DOM which makes DOM manipulation easier.
Props are used to pass data from one component to another. The state is local data storage that is
PROPS STATE
Props can be used with state and The state can be used only with the state
update and render the user interface by comparing the current and previous virtual DOM states using
Efficient Rendering: The Virtual DOM is an in-memory representation of the actual DOM that
Diffing Algorithm: React compares the current and previous versions of the Virtual DOM using
a diffing algorithm, identifying the minimal set of changes required to update the real DOM.
Batch Updates: Instead of updating the real DOM immediately, React batches multiple
Faster Updates: Since updating the real DOM is slow, React minimizes direct DOM
manipulations by only making updates where necessary after comparing the Virtual DOM.
Declarative UI: With the Virtual DOM, React allows developers to write code in a declarative
style, letting React handle when and how to efficiently update the UI.
Slower as it requires direct updates Faster because it minimizes direct manipulation of the Real
Directly manipulates the Real DOM, Updates are made to the Virtual DOM first, then changes
causing re-rendering of the entire are batched and only the necessary changes are reflected
Entire UI might need to be re- Only the necessary components are re-rendered, reducing
Less efficient due to repeated direct More efficient by minimizing direct DOM manipulation and
8. What is JSX?
JSX is basically a syntax extension of regular JavaScript and is used to create React elements. These
elements are then rendered to the React DOM. All the React components are written in JSX. To embed
any JavaScript expression in a piece of code written in JSX we will have to wrap that expression in
const element = (
<h1>
Hello,
{name}.Welcome to GeeksforGeeks.
</h1>
);
A Component is one of the core building blocks of React. In other words, we can say that every
application you will develop in React will be made up of pieces called components. Components make
Class Components: The class components are a little more complex than the functional
components. The functional components are not aware of the other components in your
program whereas the class components can work with each other. We can pass data from one
In general, browsers are not capable of reading JSX and only can read pure JavaScript. The web
browsers read JSX with the help of a transpiler. Transpilers are used to convert JSX into JavaScript.
11. Explain the steps to create a react application and print Hello World?
To install React, first, make sure Node is installed on your computer. After installing Node. Open the
Note: The above method is now deprecated, so use the below given method for creating the React
application.
cd <<Application_Name>>
import "./App.css";
function App() {
Output:
npm start
React app
To create an event in React, attach an event handler like onClick, onChange, etc., to a JSX element.
Define the handler function to specify the action when the event is triggered, such as updating state
or executing logic.
function Component() {
doSomething(e);
e.preventDefault();
Lists are very useful when it comes to developing the UI of any website. Lists are mainly used for
displaying menus on a website. To create a list in React use the map method of array as follows.
});
Output:
List
A key is a special string attribute you need to include when creating lists of elements in React. Keys
are used in React to identify which items in the list are changed, updated, or deleted. In other words,
we can say that keys are used to give an identity to the elements in the lists.
Multi-line comment: We can write multi-line comments in React using the asterisk format /*
*/.
/*
*/
Single line comment: We can write single comments in React using the double forward slash
//.
React Angular
updates only the virtual DOM is present and the data the Real DOM and the data flow is ensured
It supports Uni-directional data binding which is one- It supports Bi-directional data binding
React renders HTML to the web page by using a function called render(). The purpose of the function
is to display the specified HTML code inside the specified HTML element. In the render() method, we
can read props and state and return our JSX code to the root component of our app.
The state is an instance of React Component Class that can be defined as an object of a set of
observable properties that control the behaviour of the component. In other words, the State of a
component is an object that holds some information that may change over the lifetime of the
component.
React allows us to pass information to a Component using something called props (which stands for
We can access any props inside from the component’s class to which the props is passed. The props
Higher-order components or HOC is the advanced method of reusing the component functionality
logic. It simply takes the original component and returns the enhanced component. HOC are beneficial
as they are easy to code and read. Also, helps to get rid of copying the same logic in every component.
21. Explain the difference between functional and class component in React?
A functional component is just a plain JavaScript A class component requires you to extend from
pure function that accepts props as an React. Component and create a render
argument function
No render method used It must have the render() method returning JSX
React lifecycle methods (for example, React lifecycle methods can be used inside
ReactJS uses one-way data binding which can be Component to View or View to Component. It is
also known as one-way data flow, which means the data has one, and only one way to be transferred
to other parts of the application. In essence, this means child components are not able to update the
data that is coming from the parent component. It is easy to debug and less prone to errors.
The Context API is a way to share data (such as theme, language preference, etc.) across
components without having to pass props down manually at every level. It provides a Provider
component to set the value and a Consumer component or useContext() hook to access it.
should re-render when it receives new props or state. If it returns false, React will skip the re-render
discouraged because it can expose the application to XSS (cross-site scripting) attacks, but it is
A Pure Component is a type of React component that only re-renders if the props or state it receives
change. React provides React.PureComponent, which is a base class that automatically performs a
setState() is a method used to update the state of a component. When the state is updated, React re-
renders the component and its child components to reflect the changes.
Here, we cover all intermediate level react interview questions with answers, that recommeded for
conditions. By evaluating these conditions, developers can control which components are displayed,
Here if the boolean isLoggedIn is false then the DisplayLoggedOut component will be rendered
various components in a React Application, allows changing the browser URL, and keeps the UI in
npm i react-router-dom
all of the other components. Everything within this will be part of the routing functionality
2. Switch: The switch component is used to render only the first route that matches the location
3. Route: This component checks the current URL and displays the component associated with
that exact path. All routes are placed within the switch components.
No full page reloads. React updates only the Full page reload is triggered for every
React uses a client-side router (e.g., React Uses server-side routing where the server
Router) to handle navigation and manage different responds with new HTML for each
Routes are managed by JavaScript, and the Routes correspond to different server-side
browser’s address bar reflects the application’s routes, and the server responds with new
Initialization: This is the stage where the component is constructed with the given Props and
Mounting: Mounting is the stage of rendering the JSX returned by the render method itself.
Updating: Updating is the stage when the state of a component is updated and the application
is repainted.
Unmounting: As the name suggests Unmounting is the final step of the component lifecycle
and the component is mounted on the DOM and rendered for the first time on the webpage. he
componentDidMount() Function: This function is invoked right after the component is mounted
on the DOM.
We use the setState() method to change the state object. It ensures that the component has been
updated and calls for re-rendering of the component. The state object of a component may contain
multiple attributes and React allows using setState() function to update only a subset of those
attributes as well as using multiple setState() methods to update each attribute value independently.
Refs are a function provided by React to access the DOM element and the React element that you
might have created on your own. They are used in cases where we want to change the value of a
child component, without making use of props and all. They have wide functionality as we can use
without writing a class. Hooks doesn’t violate any existing React concepts. Instead, Hooks provide a
direct API to react concepts such as props, state, context, refs and life-cycle
The most used hook in React is the useState() hook. Using this hook we can declare a state variable
inside a function but only one state variable can be declared using a single useState() hook. Whenever
the useState() hook is used, the value of the state variable is changed and the new variable is stored
Syntax:
The useEffect hook in React eliminates the side effect of using class based components. It is used as
an alternative to componentDidUpdate() method. The useEffect hook accepts two arguments where
useEffect(function, dependency)
The dependency decides when the component will be updated again after rendering.
‘div’ tag which is not loved by many developers. So since React 16.2 version, Fragments were
introduced, and we use them instead of the extraneous ‘div’ tag. The following syntax is used to create
fragment in react.
<React.Fragment>
<h2>Child-1</h2>
<p> Child-2</p>
</React.Fragment>
React Developer Tools is a Chrome DevTools extension for the React JavaScript library. A very useful
tool, if you are working on React applications. This extension adds React debugging tools to the
Chrome Developer Tools. It helps you to inspect and edit the React component tree that builds the
page, and for each component, one can check the props, the state, hooks, etc.
CSS modules are a way to locally scope the content of your CSS file. We can create a CSS module
file by naming our CSS file as App.modules.css and then it can be imported inside App.js file using
Syntax:
way in React. Instead of having one global CSS file for a React project, we can use styled-component
for enhancing the developer experience. It also removes the mapping between components and styles
npm i styled-components
width : 100px ;
cursor: pointer ;
text-decoration : none;
Prop drilling is basically a situation when the same data is being sent at almost every level due to
requirements in the final level. The problem with Prop Drilling is that whenever data from the Parent
component will be needed, it would have to come from each level, Regardless of the fact that it is not
Conditional rendering in React is used when you want to render different UI elements based on certain
conditions. For example, rendering a login button if a user is not logged in or rendering a logout button
return (
<div>
</div>
);
Controlled components are React components where the form data is handled by the state within the
component. The form element's value is controlled via the React state, making the form elements
responsive to changes.
For further reading, check out our dedicated article on Intermediate ReactJS Intermediate Interview
Here, we cover advanced react interview questions with answers for experienced professionals,
hooks. We use custom hooks to maintain the DRY concept that is Don’t Repeat Yourself. It helps us
Eliminating the use of inline attributes as they slow the process of loading
Lazy loading
useRef createRef
It is a hook. It is a function.
It uses the same ref throughout the component's It creates a new ref every time component
lifecycle. re-renders.
It returns a mutable ref object (i.e., can be It returns a read-only ref object (cannot
React-redux is a state management tool which makes it easier to pass these states from one
component to another irrespective of their position in the component tree and hence prevents the
complexity of the application. As the number of components in our application increases it becomes
difficult to pass state as props to multiple components. To overcome this situation we use react-redux
It provides centralized state management i.e. a single store for whole application
Since it offers persistent state management therefore storing data for long times become easier
51. Explain the core components of react-redux?
There are four fundamental concepts of redux in react which decide how the data will flow through
components
Actions: Actions are simple objects which conventionally have two properties- type and
payload
Reducers: Reducers are pure functions that update the state of the application in response to
actions
When working with Redux we sometimes require multiple reducers. In many cases, multiple actions
are needed, resulting in the requirement of multiple reducers. However, this can become problematic
when creating the Redux store. To manage the multiple reducers we have function called
combineReducers in the redux. This basically helps to combine multiple reducers into a single unit
Syntax
books: BooksReducer,
activeBook: ActiveBook
});
In ReactJS, Cross-Origin Resource Sharing (CORS) refers to the method that allows you to make
requests to the server deployed at a different domain. As a reference, if the frontend and backend are
axios
fetch
Axios, which is a popular library is mainly used to send asynchronous HTTP requests to REST
This popular library is used to communicate with the backend. Axios supports the Promise API,
native to JS ES6.
Using Axios we make API requests in our application. Once the request is made we get the
npm i axios
We can create the counter app with increment and decrement by writing the below code in the
terminal:
import React, { useState } from "react";
setCounter(counter + 1)
setCounter(counter - 1)
return (
<div>
<div>
{counter}
</div>
<div className="buttons">
<button onClick={handleClick1}>
Increment
</button>
<button onClick={handleClick2}>
Decrement
</button>
</div>
</div>
Output:
56. Explain why and how to update state of components using callback?
It is advised to use a callback-based approach to update the state using setState because it solves
lots of bugs upfront that may occur in the future.We can use the following syntax to update state using
callback
this.setState(st => {
return(
st.stateName1 = state1UpdatedValue,
st.stateName2 = state2UpdatedValue
})
React Material UI is an open-source React component library, offering prebuilt components for
creating React applications. Developed by Google in 2014, it's compatible with JavaScript frameworks
like Angular.js and Vue.js. Renowned for its quality designs and easy customization, it's favored by
Flux architecture in Redux is a design pattern used for managing application state in a unidirectional
data flow. In this architecture, actions are dispatched to modify the store, which holds the entire
application state. The store sends the updated state to the view (UI), and the cycle repeats when new
actions are triggered. Redux follows this structure to ensure a predictable and maintainable state
Custom hooks are user-defined functions that use built-in hooks like useState, useEffect, etc., to reuse
stateful logic across components. They allow you to extract and share common logic.
Strict Mode in React is a tool that helps developers find and fix problems in their app while developing.
It only works in development and doesn’t affect the app when it’s running in production. When enabled,
it checks for potential issues, such as old features that should no longer be used, and gives warnings
We can enable the strict mode by by wrapping your application or specific components inside
the <React.StrictMode>.
return (
<div>
<h1>Hello, World!</h1>
</div>
);
};
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
Redux is a state management library that helps manage the application state globally. It uses actions,
reducers, and a central store to control state. React-Redux is used to connect Redux state to React
components.
React's Concurrent Mode is a set of features that help React apps stay responsive and gracefully
adjust to the user’s device capabilities and network speed. It allows React to interrupt rendering and
the fully rendered HTML to the client. This improves the initial page load performance and SEO.
In React, forms are a way to capture user input, such as text fields, checkboxes, radio buttons, and
buttons. React provides controlled and uncontrolled components for handling form elements, allowing
developers to manage user input and form state in an efficient and structured way.
Creating forms in React involves handling user input and managing the form's state. In React, form
elements like <input>, <textarea>, and <select> are controlled components, meaning their values are
Create the State for the Form: Use the useState hook to manage form input values.
Set the Value of Form Elements: Bind the form elements’ value attribute to the corresponding
Handle User Input: Use an onChange event handler to update the state whenever the user
Submit the Form: Handle the form submission with an onSubmit event, and prevent the
function MyForm() {
};
return (
<form onSubmit={handleSubmit}>
<div>
<label>Name:</label>
</div>
<div>
<label>Email:</label>
</div>
<div>
<label>Message:</label>
</div>
<button type="submit">Submit</button>
</form>
);
Output:
React Form
Lazy Loading in React is a technique used to load components only when they are needed, instead
of loading everything at once when the app starts. This helps improve the performance of the app by
In React, React.lazy() is used to implement lazy loading for components, which allows you to split your
code into smaller bundles and load them only when required.
A JavaScript library for building user A framework for building mobile applications using
Uses web technologies like HTML, CSS, Uses native mobile components and styles for
Can be deployed on browsers like Chrome, Can be deployed as native apps on iOS and Android
by preventing unnecessary re-renders. It involves caching the results of expensive function calls and
reusing the cached result when the inputs to the function haven't changed. This is particularly useful
when a component’s rendering process is slow, and you want to avoid recalculating or re-rendering
unnecessarily.
Reconciliation in React is the process of updating the DOM when a component's state or props
change. React uses the Virtual DOM to efficiently determine what parts of the actual DOM need to
Triggering Reconciliation: React triggers reconciliation when state or props change (e.g.,
Virtual DOM Diffing: React compares the old Virtual DOM with the new one to identify
changes.
Efficient Updates: React calculates the minimal set of changes and applies them to the real
DOM.
Fiber Algorithm: React's Fiber algorithm allows the reconciliation process to be interrupted
conditions. By evaluating these conditions, developers can control which components are displayed,
Here if the boolean isLoggedIn is false then the DisplayLoggedOut component will be rendered
React Router is a standard library for routing in React. It enables the navigation among views of
various components in a React Application, allows changing the browser URL, and keeps the UI in
npm i react-router-dom
all of the other components. Everything within this will be part of the routing functionality
2. Switch: The switch component is used to render only the first route that matches the location
3. Route: This component checks the current URL and displays the component associated with
that exact path. All routes are placed within the switch components.
No full page reloads. React updates only the Full page reload is triggered for every
React uses a client-side router (e.g., React Uses server-side routing where the
Router) to handle navigation and manage different server responds with new HTML for each
Routes are managed by JavaScript, and the Routes correspond to different server-side
browser’s address bar reflects the application’s routes, and the server responds with new
Initialization: This is the stage where the component is constructed with the given Props and
Mounting: Mounting is the stage of rendering the JSX returned by the render method itself.
Updating: Updating is the stage when the state of a component is updated and the application
is repainted.
Unmounting: As the name suggests Unmounting is the final step of the component lifecycle
Mounting is the phase of the component lifecycle when the initialization of the component is completed
and the component is mounted on the DOM and rendered for the first time on the webpage. he
componentDidMount() Function: This function is invoked right after the component is mounted
on the DOM.
We use the setState() method to change the state object. It ensures that the component has been
updated and calls for re-rendering of the component. The state object of a component may contain
multiple attributes and React allows using setState() function to update only a subset of those
attributes as well as using multiple setState() methods to update each attribute value independently.
Refs are a function provided by React to access the DOM element and the React element that you
might have created on your own. They are used in cases where we want to change the value of a
child component, without making use of props and all. They have wide functionality as we can use
Hooks are a new addition in React 16.8. They let developers use state and other React features
without writing a class. Hooks doesn’t violate any existing React concepts. Instead, Hooks provide a
direct API to react concepts such as props, state, context, refs and life-cycle
The most used hook in React is the useState() hook. Using this hook we can declare a state variable
inside a function but only one state variable can be declared using a single useState() hook. Whenever
the useState() hook is used, the value of the state variable is changed and the new variable is stored
Syntax:
The useEffect hook in React eliminates the side effect of using class based components. It is used as
an alternative to componentDidUpdate() method. The useEffect hook accepts two arguments where
useEffect(function, dependency)
The dependency decides when the component will be updated again after rendering.
39. What is React Fragments?
when we are trying to render more than one root element we have to put the entire content inside the
‘div’ tag which is not loved by many developers. So since React 16.2 version, Fragments were
introduced, and we use them instead of the extraneous ‘div’ tag. The following syntax is used to create
fragment in react.
<React.Fragment>
<h2>Child-1</h2>
<p> Child-2</p>
</React.Fragment>
React Developer Tools is a Chrome DevTools extension for the React JavaScript library. A very useful
tool, if you are working on React applications. This extension adds React debugging tools to the
Chrome Developer Tools. It helps you to inspect and edit the React component tree that builds the
page, and for each component, one can check the props, the state, hooks, etc.
CSS modules are a way to locally scope the content of your CSS file. We can create a CSS module
file by naming our CSS file as App.modules.css and then it can be imported inside App.js file using
Syntax:
way in React. Instead of having one global CSS file for a React project, we can use styled-component
for enhancing the developer experience. It also removes the mapping between components and styles
npm i styled-components
width : 100px ;
cursor: pointer ;
text-decoration : none;
Prop drilling is basically a situation when the same data is being sent at almost every level due to
requirements in the final level. The problem with Prop Drilling is that whenever data from the Parent
component will be needed, it would have to come from each level, Regardless of the fact that it is not
Conditional rendering in React is used when you want to render different UI elements based on certain
conditions. For example, rendering a login button if a user is not logged in or rendering a logout button
return (
<div>
</div>
);
Controlled components are React components where the form data is handled by the state within the
component. The form element's value is controlled via the React state, making the form elements
responsive to changes.
For further reading, check out our dedicated article on Intermediate ReactJS Intermediate Interview
Here, we cover advanced react interview questions with answers for experienced professionals,
hooks. We use custom hooks to maintain the DRY concept that is Don’t Repeat Yourself. It helps us
Eliminating the use of inline attributes as they slow the process of loading
Lazy loading
useRef createRef
It is a hook. It is a function.
It uses the same ref throughout the component's It creates a new ref every time component
lifecycle. re-renders.
React-redux is a state management tool which makes it easier to pass these states from one
component to another irrespective of their position in the component tree and hence prevents the
complexity of the application. As the number of components in our application increases it becomes
difficult to pass state as props to multiple components. To overcome this situation we use react-redux
It provides centralized state management i.e. a single store for whole application
Since it offers persistent state management therefore storing data for long times become easier
51. Explain the core components of react-redux?
There are four fundamental concepts of redux in react which decide how the data will flow through
components
Actions: Actions are simple objects which conventionally have two properties- type and
payload
Reducers: Reducers are pure functions that update the state of the application in response to
actions
When working with Redux we sometimes require multiple reducers. In many cases, multiple actions
are needed, resulting in the requirement of multiple reducers. However, this can become problematic
when creating the Redux store. To manage the multiple reducers we have function called
combineReducers in the redux. This basically helps to combine multiple reducers into a single unit
Syntax
books: BooksReducer,
activeBook: ActiveBook
});
In ReactJS, Cross-Origin Resource Sharing (CORS) refers to the method that allows you to make
requests to the server deployed at a different domain. As a reference, if the frontend and backend are
axios
fetch
Axios, which is a popular library is mainly used to send asynchronous HTTP requests to REST
This popular library is used to communicate with the backend. Axios supports the Promise API,
native to JS ES6.
Using Axios we make API requests in our application. Once the request is made we get the
npm i axios
We can create the counter app with increment and decrement by writing the below code in the
terminal:
import React, { useState } from "react";
setCounter(counter + 1)
setCounter(counter - 1)
return (
<div>
<div>
{counter}
</div>
<div className="buttons">
<button onClick={handleClick1}>
Increment
</button>
<button onClick={handleClick2}>
Decrement
</button>
</div>
</div>
Output:
56. Explain why and how to update state of components using callback?
It is advised to use a callback-based approach to update the state using setState because it solves
lots of bugs upfront that may occur in the future.We can use the following syntax to update state using
callback
this.setState(st => {
return(
st.stateName1 = state1UpdatedValue,
st.stateName2 = state2UpdatedValue
})
React Material UI is an open-source React component library, offering prebuilt components for
creating React applications. Developed by Google in 2014, it's compatible with JavaScript frameworks
like Angular.js and Vue.js. Renowned for its quality designs and easy customization, it's favored by
Flux architecture in Redux is a design pattern used for managing application state in a unidirectional
data flow. In this architecture, actions are dispatched to modify the store, which holds the entire
application state. The store sends the updated state to the view (UI), and the cycle repeats when new
actions are triggered. Redux follows this structure to ensure a predictable and maintainable state
Custom hooks are user-defined functions that use built-in hooks like useState, useEffect, etc., to reuse
stateful logic across components. They allow you to extract and share common logic.
Strict Mode in React is a tool that helps developers find and fix problems in their app while developing.
It only works in development and doesn’t affect the app when it’s running in production. When enabled,
it checks for potential issues, such as old features that should no longer be used, and gives warnings
We can enable the strict mode by by wrapping your application or specific components inside
the <React.StrictMode>.
return (
<div>
<h1>Hello, World!</h1>
</div>
);
};
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
Redux is a state management library that helps manage the application state globally. It uses actions,
reducers, and a central store to control state. React-Redux is used to connect Redux state to React
components.
React's Concurrent Mode is a set of features that help React apps stay responsive and gracefully
adjust to the user’s device capabilities and network speed. It allows React to interrupt rendering and
the fully rendered HTML to the client. This improves the initial page load performance and SEO.
In React, forms are a way to capture user input, such as text fields, checkboxes, radio buttons, and
buttons. React provides controlled and uncontrolled components for handling form elements, allowing
developers to manage user input and form state in an efficient and structured way.
Creating forms in React involves handling user input and managing the form's state. In React, form
elements like <input>, <textarea>, and <select> are controlled components, meaning their values are
Create the State for the Form: Use the useState hook to manage form input values.
Set the Value of Form Elements: Bind the form elements’ value attribute to the corresponding
Handle User Input: Use an onChange event handler to update the state whenever the user
Submit the Form: Handle the form submission with an onSubmit event, and prevent the
function MyForm() {
};
return (
<form onSubmit={handleSubmit}>
<div>
<label>Name:</label>
</div>
<div>
<label>Email:</label>
</div>
<div>
<label>Message:</label>
</div>
<button type="submit">Submit</button>
</form>
);
Output:
React Form
Lazy Loading in React is a technique used to load components only when they are needed, instead
of loading everything at once when the app starts. This helps improve the performance of the app by
In React, React.lazy() is used to implement lazy loading for components, which allows you to split
your code into smaller bundles and load them only when required.
A JavaScript library for building user A framework for building mobile applications using
Uses web technologies like HTML, CSS, Uses native mobile components and styles for
Can be deployed on browsers like Chrome, Can be deployed as native apps on iOS and Android
by preventing unnecessary re-renders. It involves caching the results of expensive function calls and
reusing the cached result when the inputs to the function haven't changed. This is particularly useful
when a component’s rendering process is slow, and you want to avoid recalculating or re-rendering
unnecessarily.
Reconciliation in React is the process of updating the DOM when a component's state or props
change. React uses the Virtual DOM to efficiently determine what parts of the actual DOM need to
Triggering Reconciliation: React triggers reconciliation when state or props change (e.g.,
Virtual DOM Diffing: React compares the old Virtual DOM with the new one to identify
changes.
Efficient Updates: React calculates the minimal set of changes and applies them to the real
DOM.
Fiber Algorithm: React's Fiber algorithm allows the reconciliation process to be interrupted
1. What is React?
React?
6. What are React Hooks?
9. What is JSX?