React
React
React then takes the updated Virtual DOM and uses it to update the
actual DOM, minimizing the amount of work that needs to be done in the
actual DOM and improving the overall performance of the application.
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. The
transpiler used is called Babel
Controlled Components
1. They do not maintain their own state
2. Data is controlled by the parent component
3. They take in the current values through props and then notify the
changes via callbacks
Uncontrolled Components
1. They maintain their own state.
2. Data is controlled by the DOM.
3. Refs are used to get their current values
Q7. What is the use of ref in React?
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 callbacks with them.
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 needed there and simply needed in the last.
Q9. What are custom hooks in React?
Custom hooks are normal JavaScript functions whose names start with
“use”, and they may call other hooks. We use custom hooks to maintain
the DRY concept that is Do not Repeat Yourself. It helps us to write a
logic once and use it anywhere in the code.
Store – State/ Object tree of the entire application is saved in the Store.
In case you are facing any challenges with these React interview
questions, please comment on your problems in the section below.
There are several techniques that can be used to optimize a large React
application:
Use the useEffect hook to handle side effects. This hook allows you to
run side effects, such as network requests, after a component has
rendered.
Use the useMemo hook to memoize expensive calculations. This hook
allows you to cache the results of expensive calculations and only
recalculate them when the inputs have changed.
Lazy loading: Lazy loading is a technique where you only load the
components that are needed for the current view. This can greatly
improve the performance of your application.
Input validation: Validate all user inputs on the client and server side to
prevent any malicious data from being processed.
Redux Thunk middleware allows you to write action creators that return
a function instead of an action. The thunk can be used to delay the
dispatch of an action or to dispatch only if a certain condition is met. The
inner function receives the store methods dispatch() and getState() as
parameters.