React
React
1. What is React?
React is an open source JavaScript Library.
React is used for building user interfaces (UI).
React simplifies the crea on of SPA by using reusable components.
13. What are state, stateless, stateful and state management terms?
"state" refers to the current data of the component.
Stateful or state management means, when a user performs some
ac ons on the UI, then the React applica on should be able to update
and re-render that data or state on the UI.
14. What are Props n JSX? V. IMP.
props (proper es) are a way to pass data from a parent component to a
child component.
15. What is the role of index.js file and ReactDOM in React? V. IMP.
ReactDOM is a JavaScript library that renders components to the DOM or
browser.
The index.js file is the JavaScript file that replaces the root element of
the index.html file with the newly rendered components.
16. What is the role of App.js file in React? V. IMP.
App.js file contain the root component(App) of React applica on.
App component is like a container for other components.
App.js defines the structure, layout, and rou ng in the applica on.
22. What are React Hooks? What are the Top React Hooks? V. IMP.
React Hooks are inbuilt func ons provided by React that allow func onal
components to use state and lifecycle features.
Before Hooks, class components lifecycle methods were used to
maintain state in React applica ons.
To use React Hook first we first have to import it from React library.
23. What is the role of useState() hook and how it works? V. IMP.
The useState hook enables func onal components to manage state.
useState() working: usestate() func on accept the ini al state value as
the parameter and returns an array with two elements:
The first element is the current state value (count in this code).
Second element is the func on that is used to update the state (setCount
in this code).
The concept of assign array elements to individual variables is called
array destructuring.
24. What is the role of useEffect(). How it works and what is its use? V. IMP.
The use Effect Hook in React is used to perform side effects in func onal
components.
For example, data fetching from API, subscrip ons or any other
opera on that needs to be performed a er the component has been
rendered.
useEffect() is called a er the component renders. Example, side effects.
useEffect() func on will accept two parameter: (Effect func on,
dependency array).
28. When to use useContext() hook instead of props in real applica ons?
Use useContext instead of props when you want to avoid prop drilling
and access context values directly within deeply nested components.
29. What are components life cycle phases?