React Interview Questions
React Interview Questions
● React
○ Javascript library to build user interface
○ Multiple components can be composed together.
○ Create single page application
● Advantages of React
○ Light weight
○ High efficiency
○ Reusable components
● Disadvantages of React
● Babel Js
○ Babel is a javascript compiler that translates javascript code into
older versions of javascript, compatible with old browsers and
environments.
● React components lifecycle
● Mounting Phase
Constructor, static getDerivedStateFromProps,render(), componentdidmount()
● Updating Phase
staticgetDerivedStateFromProps,ShouldComponentUpdate(),render(),getSnapsh
otBeforeUpdate(),ComponentDidUpdate()
● Unmounting Phase
Componentwillunmount
React takes charge manages the input Browser handles it, React stays out of it
value.
React manages and trackes the value in Html form element dom manages and tracks value
state i.e state handled like the value
Mouse clicks The button click event retrieves the input value
directly from the DOM. useref
● State vs Props
State Props
Like variable declared in the function. Props are known as properties used to pass data
Data is passed within the component from one component to another.
Immutable mutable
State only with the class component Props can also in class and function component
Class component with extend and render Simple javascript function accept props as
function return jsx argument and return jsx
● What is Redux
○ Redux is a light weight js library to develop the architecture
○ Reduce complexity and carry more data
○ state management
■ Storing all application state in one place “store”, dispatch
● Reducer in redux
○ Current state and action can be combined to create new store.
○ Modifying the state
● Diff b/w flux and redux
○ Flux - design pattern
○ Redux - develop quick design pattern
● Prop drilling
● Tuneeliing
● Pure component
○ When a pure component receives new props or updates its state, it
compares the new values with the previous values using a shallow
equality check. If the values are the same, the component won't re-render,
saving unnecessary rendering and reconciliation work.
○ React applications by reducing unnecessary re-renders.
○ ike pure components by default, thanks to React's reconciliation algorithm
and the use of React hooks like React.memo() or useMemo().
○ Also known as functional component, React.memo
● Higher order components
○ A higher-order component (HOC) is a function that takes a component as
an argument and returns a new component with enhanced functionality. It
allows for the reuse and composition of component logic in React.
■ Reusability
■ Separation of concerns
● Virtual dom
Creates copy of real dom displays the output compares the old and new dom and
update it neededone.
1. Element vs component
2. Purecomponent ref useref