React is a JavaScript library created by Facebook. It is a User Interface (UI) library that is use for building UI components. Although React is a library rather than a language, it is widely used in web development. React offers various extensions for entire application architectural support, such as Flux and React Native, beyond mere UI.
React is a front-end JavaScript library developed by Facebook in 2011.
Even though it was open-sourced only in 2015, it has one of the largest communities supporting it.
It is used for developing complex and interactive web and mobile UI.
It follows the component based approach which helps in building reusable UI components.
Q2. Why should we use React?
Easy creation of dynamic applications
Improved performance
Reusable components
Dedicated tools for easy debugging
Small learning curve
Unidirectional data flow
Q3. Main features of React?
Virtual Document Object Model (DOM)
JSX
Components in React
Architecture
Props in React
Extensions
Data Binding
Debugging
State in React
Q4. What is useCallback?
Pass an inline callback and an array of dependencies. useCallback will return a memoized version of the callback that only changes if one of the dependencies has changed.
This is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders (e.g. shouldComponentUpdate).
Q5. What is useRef?
useRef returns a mutable ref object whose current property is initialized to the passed argument (initialValue).
The returned object will persist for the full lifetime of the component.
Q6. What is PureComponent?
If your React component’s render() function renders the same result given the same props and state, you can use React.PureComponent for a performance boost in some cases(if your previous and new value are same then component will not re-render).
Q7. What is Suspense?
This is all less complicated than it may seem. Traditionally in React, you’d set state, and your UI would update. Life was simple. But it also led to the sorts of inconsistencies described above.
What Suspense adds is the ability to have a component notify React at render time that it’s waiting for asynchronous data. This is called suspending, and it can happen anywhere in a component’s tree, as many times as needed, until the tree is ready. When a component suspends, React will decline to render the pending state update until all suspended dependencies have been satisfied.
A higher-order component (HOC) is an advanced technique in React for reusing component logic.
HOCs are not part of the React API. They are a pattern that emerges from React’s compositional nature. We need an abstract method so we use HOC as abstract class. Abstraction that allows us to define this logic in a single place and share it across components.
(An abstract class is a class that contains at least one abstract method. An abstract method is a method that is declared, but not implemented in the code. An abstract class or method is defined with the abstract keyword).
Concretely, a higher-order component is a function that takes a component and returns a new component. In javascript, Callback Functions is called HOC.
Q9. What about Component Lifecycle?
The Component Lifecycle
Each component has several “lifecycle methods” that you can override to run code at particular times in the process.
In the list below, commonly used lifecycle methods are marked as --. The rest of them exist for relatively rare use cases.
A) Mounting
These methods are called in the following order when an instance of a component is being created and inserted into the DOM:
Note:
These methods are considered legacy and you should avoid them in new code:
UNSAFE_componentWillMount()
B) Updating
An update can be caused by changes to props or state. These methods are called in the following order when a component is being re-rendered:
Note:
These methods are considered legacy and you should avoid them in new code:
UNSAFE_componentWillUpdate()
UNSAFE_componentWillReceiveProps()
C) Unmounting
This method is called when a component is being removed from the DOM:
componentWillUnmount() --
Q10. What is Test Renderer?
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM or a native mobile environment.
Q11. Alternative to componentDidMount, componentDidUpdate and componentWillUnmount in functional component?
The Effect Hook, useEffect, adds the ability to perform side effects from a function component. It serves the same purpose as componentDidMount, componentDidUpdate, and componentWillUnmount in React classes, but unified into a single API.
Q12. Why is useState not named createState instead?
"Create" wouldn’t be quite accurate because the state is only created the first time our component renders. During the next renders, useState gives us the current state.
Otherwise it wouldn’t be “state” at all! There’s also a reason why Hook names always start with use.
Q13. What should I do to Optimizing Performance by Skipping Effects, means useEffect?
This requirement is common enough that it is built into the useEffect Hook API. You can tell React to skip applying an effect if certain values haven’t changed between re-renders. To do so, pass an array as an optional second argument to useEffect:
useEffect(() => {
document.title = `You clicked ${count} times`;
}, [count]); // Only re-run the effect if count changes
Note:- In the example above, we pass [count] as the second argument. What does this mean? If the count is 5, and then our component re-renders with count still equal to 5,
React will compare [5] from the previous render and [5] from the next render. Because all items in the array are the same (5 === 5), React would skip the effect.
That’s our optimization.
When we render with count updated to 6, React will compare the items in the [5] array from the previous render to items in the [6] array from the next render.
This time, React will re-apply the effect because 5 !== 6. If there are multiple items in the array, React will re-run the effect even if just one of them is different.
Q14. What is HTML DOM createElement() Method?
The createElement() method creates an element node with the specified name.
It takes 3 parameter
1: Attribute
2: Class
3: Text
Q15. Can you initialize state from a function? Provide an example?
Refs is the short hand for References in React. It is an attribute which helps to store a reference to a particular React element or component, which will be returned by the components render config function.
Q18. List some of the cases when you should use Refs?
When you need to manage focus, select text or media playback
To trigger imperative animations
Integrate with third-party DOM library.
Q19. What can you do with HOC?
HOC can be used for many tasks like:
Code reuse, logic and bootstrap abstraction
Render High jacking
State abstraction and manipulation
Props manipulation
Q20. What are the limitations of React?
Limitations of React are listed below:
Its library is very large and takes time to understand
Coding gets complex as it uses inline templating and JSX
It can be little difficult for the novice programmers to understand
React is just a library, not a full-blown framework
Q21. Difference between Props vs. State in React?
Props
State
Props are immutable — they can't be modified after they've been set.
The data is stored in the state, which might change over time.
Props are used to send data and event handlers to a component's children.
The data of the components that must be presented to it store the view in the state.
The parent component sets props for the children components.
Event handlers are typically responsible for updating the state.
Both functional and class components can benefit from the use of props.
Only class components can use the state.
Q22. What is the significance of keys in React?
Keys are used for identifying unique Virtual DOM Elements with their corresponding data driving the UI.
They help React to optimize the rendering by recycling all the existing elements in the DOM.
These keys must be a unique number or string, using which React just reorders the elements instead of re-rendering them.
This leads to increase in application’s performance.
Q23. What is Flux?
Flux is an architectural pattern which enforces the uni-directional data flow.
It is not a library nor a framework.
It controls derived data and enables communication between multiple components using a central Store which has authority for all data.
Any update in data throughout the application must occur here only. Flux provides stability to the application and reduces run-time error.
Flux applications have three major roles in dealing with data: 1. Dispatcher 2. Stores 3. Views (React components)
Q24. List down the components of Redux?
Redux is composed of the following components:
Action :– It’s an object that describes what happened.
Reducer :– It is a place to determine how the state will change.
Store :– State/ Object tree of the entire application is saved in the Store.
View :– Simply displays the data provided by the Store.
Q25. What is JSX?
JSX is a shorthand for JavaScript XML. It is a React extension which allows writing JavaScript code that looks similar to HTML.
It makes HTML file easy to understand. The JSX file makes the React application robust and boosts its performance.
JSX provides you to write XML-like syntax in the same file where you write JavaScript code, and then preprocessor (i.e: transpilers like Babel) transform these expressions into actual JavaScript code. Just like XML/HTML, JSX tags have a tag name, attributes, and children.
Browsers cannot read JSX directly because they can only understand JavaScript objects, and JSX is not a regular JavaScript object.
Thus, we need to transform the JSX file into a JavaScript object using transpilers like Babel and then pass it to the browser.
Q27. Why is switch keyword used in React Router v4?
Although a <div> is used to encapsulate multiple routes inside the router. The 'switch' keyword is used when you want to display only a single route to be rendered amongst the several defined routes.
The <switch> tag when in use matches the typed URL with the defined routes in sequential order. When the first match is found, it renders the specified route. Thereby bypassing the remaining routes.
Q28. What is Context API?
There have 3 property:
createContext, Provider and UseContext.
Simply we can say, Provider and Consumer concept. Here we replace Consumer with useContext() hook.
Q29. What is the second argument that can optionally be passed to setState and what is it's purpose?
A callback function which will be invoked when setState has finished and the component is re-rendered. It is used for show response on browser or console.
Since the setState is asynchronous, which is why it takes in a second callback function. With this function, we can do what we want immediately after state has been updated.
Q30. What is context?
Context provides a way to pass data through the component tree without having to pass props down manually at every level.
Q31. How different is React’s ES6 syntax when compared to ES5?
require vs import:
// ES5
var React = require('react');
// ES6
import React from 'react';
export vs exports:
// ES5
module.exports = Component;
// ES6
export default Component;
Q32. What is the difference between Shadow DOM and Virtual DOM?
The Shadow dom is a browser technology designed primarily for scoping variables and CSS in web components. The Virtual don is a concept implemented by libraries in JavaScript on top of browser APIs.
Q33. What is reconciliation?
When a component's, props or state change, React decides whether an actual dom update is necessary by comparing the newly returned element with the previously rendered one. When they are not equal, React will update the DOM. This process is called reconciliation.
Q34. Difference between JSX and Babel?
JSX as we know javascript xml or extinsion. In javascript we can not direct write html code so jsx provide facility to write html directly into javascript. JSX converts HTML tags into react elements. But still our browser does not able to render this code to browser because we need a compiler that can compile html to browser so we use Babel.
Q35. What are fragments?
It's common pattern in react which is used for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.
Q36. What are the lifecycle methods going to be deprecated in React v16?
The following lifecycle methods going to be unsafe coding practices and will be more problematic with async rendering.
componentWillMount()
componentWillReceiveProps()
componentWillUpdate()
Q37. Why should component names start with capital letter?
If you are rendering your component using JSX, the name of that component has to begin with a capital letter otherwise React will thrown an error as unrecognized tag. This convention is only because HTML elements and SVG tags can begin with lowercase letter.
Q38. What is the virtual DOM?
DOM stands for Document Object Model. React keeps a lightweight representation of the real DOM in the memory, and that is known as the virtual DOM. A Virtual DOM is a lightweight JavaScript object which is an in-memory representation of real DOM. It is an intermediary step between the render function being called and the displaying of elements on the screen.
It is similar to a node tree which lists the elements, their attributes, and content as objects and their properties. The render function creates a node tree of the React components and then updates this node tree in response to the mutations in the data model caused by various actions done by the user or by the system.
When the state of an object changes, the virtual DOM changes only that object in the real DOM, rather than updating all the objects.
Q39. Can you force a component to re-render without calling setState?
By default, when your component's state or props change, your component will re-render. If your render() method depends on some other data, you can tell React that the component needs re-rendering by calling forceUpdate().
Q40. What is a state in React and how is it used?
The state is an instance of React Component Class can be defined as an object of a set of observable properties that control the behavior 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.
States are the heart of React components. States are the source of data and must be kept as simple as possible. Basically, states are the objects which determine components rendering and behavior. They are mutable unlike the props and create dynamic and interactive components.
Q41. What is the difference between super() and super(props) in React using ES6 classes?
When you want to access this.props in constructor() then you should pass props to super() method.
Q42. What is the difference between React and ReactDOM?
The react package contains React.createElement(), React.Component, React.Children, and other helpers related to elements and component classes.
You can think of these as the isomorphic or universal helpers that you need to build components. The react-dom package contains ReactDOM.render(), and in react-dom/server we have server-side rendering support.
Q43. How many parameter can take useEffect?
useEffect can take only 2 parameter.
useEffect(() => {
//Something Code Here
}, [StateOne, StateTwo])
Q44. Can we update state directly?
No, we have to use setState or useState, because it re-render component.
Q45. What is arrow function in React? How is it used?
Arrow functions are more of short syntax for writing the function expression. They are also called 'fat arrow' (=>) the functions.
These functions allow to bind the context of the components properly since in ES6 auto binding is not available by default.
Arrow functions are mostly useful while working with the higher order functions.
Q46. Why we define super in class?
With the help of super keyword, we can access all propery of parent class. Because super always used in child class or extended class or simply we can say in Inheritance.
Q47. What is the difference between ReactJS and React Native?
ReactJS
React Native
It is used for developing web applications.
It is used for developing mobile applications.
Initial release in 2013.
Initial release in 2015.
It uses a JavaScript library and CSS for animations.
It comes with built-in animation libraries.
It can be executed on all platforms.
It is not platform independent. It takes more effort to be executed on all platforms.
It uses HTML tags.
It does not use HTML tags.
Q48. What is the difference between Real DOM and Virtual DOM?
Real DOM
Virtual DOM
The real DOM can directly update HTML.
The virtual DOM cannot directly update HTML.
The real DOM updates slower.
The virtual DOM updates faster.
There is a lot of memory wastage in The real DOM.
There is no memory wastage in the virtual DOM.
In real DOM, DOM manipulation is very expensive.
In virtual DOM, DOM manipulation is very easy.
Q49. Explain the purpose of render() in React
It is mandatory for each React component to have a render() function.
Render function is used to return the HTML which you want to display in a component.
If you need to rendered more than one HTML element, you need to grouped together inside single enclosing tag such as <div>, <form>, <group> etc.
This function returns the same result each time.
import React from 'react'
class App extends React.Component {
render (){
return (
<h1>Hello From Programming Path</h1>
)
}
}
export default App
Q50. What is reducer in redux?
In Redux, a reducer is a pure function that takes an action and the previous state of the application and returns the new state.
The action describes what happened and it is the reducer's job to return the new state based on that action.
The reducer takes 2 parameters: state and action
Q51. What is an event in React?
An event is an action that a user or system may trigger, such as pressing a key, a mouse click, etc.
React events are named using camelCase, rather than lowercase in HTML.
With JSX, you pass a function as the event handler, rather than a string in HTML.
<Button onChange={showDiv} />
Q52. Differentiate between stateless and stateful components?
Stateless Component
Stateful Component
The stateless components do not hold or manage state.
The stateful components can hold or manage state.
It is also known as a functional component.
It is also known as a class component.
It does not contain the knowledge of past, current, and possible future state changes.
It can contain the knowledge of past, current, and possible future changes in state.
It is simple and easy to understand.
It is complex as compared to the stateless component.
Stateless components cannot be reused.
Stateful components can be reused.
It does not work with any lifecycle method of React.
It can work with all lifecycle method of React.
Q53. What are synthetic events in React?
The application is consistent regardless of the browser it is running in. Here, preventDefault is a synthetic event.
Synthetic events combine the response of different browser's native events into one API, ensuring that the events are consistent across different browsers.
Q54. What is Actions in redux?
Actions are objects that have a type property and any other data that it needs to describe the action.
{
type: 'ADD_MESSAGE',
message: 'Hello there!'
}
Q55. What is the purpose of getSnapshotBeforeUpdate() lifecycle method?
The new getSnapshotBeforeUpdate() lifecycle method is called right before DOM updates.
The return value from this method will be passed as the third parameter to componentDidUpdate()
Q56. What is the difference between controlled and uncontrolled components?
Controlled and Uncontrolled component differ in the way they access the data from the form elements (<input>, <textarea>, <select>). An uncontrolled component is a component that renders form elements, where the form element's data is handled by the DOM (default DOM behavior).
To access the input's DOM node and extract it's value you can use a ref.
In a controlled component, the form element's data is handled by the React component (not DOM) and kept in the component's state.
Controlled
Uncontrolled
Controlled components does not maintain its internal state.
Uncontrolled components maintains its internal states.
It accepts its current value as a prop.
It uses a ref for their current values.
Here, data is controlled by the parent component.
Here, data is controlled by the DOM itself.
It allows validation control.
It does not allow validation control.
// Uncontrolled component
const { useRef } from 'react';
function Example () {
const inputRef = useRef(null);
return
}
Forms are used for many different tasks such as user authentication, searching, filtering, indexing, etc
Using forms, users can interact with the application and enter the required information whenever needed. Form contain certain elements, such as text fields, buttons, checkboxes, radio buttons, etc
Q58. What are the different phases of React component’s lifecycle?
Initial Rendering Phase
Updating Phase
Unmounting Phase
Q59. How do you write comments in React?
#for Single line comments
/*
Multi-line comments */
Q60. What is the difference between Element and Component?
Element
Component
An element is a plain JavaScript object which describes the component state and DOM node, and its desired properties.
A component is the core building block of React application. It is a class or function which accepts an input and returns a React element.
It's immutable.
It's mutable.
It only holds information about the component type, its properties, and any child elements inside it.
It can contain state and props and has access to the React lifecycle methods.
Q61. Difference between local & session storage?
sessionStorage is likelocalStorage, the difference is that while data in localStorage doesn't expire, data in sessionStorage is cleared when the page session ends.
Features
LocalStorage
SessionStorage
Capacity
10mb
5mb
Accessible From
Any Window
Same Window
Expire
Never
On tab close
Q62. setState is an asynchronous or synchronous function?
To update the state of a component, you use the setState method. However it is easy to forget that the setState method is asynchronous, causing tricky to debug issues in your code. The setState function also does not return a Promise. Using async/await or anything similar will not work.
Q63. Why are fragments better than container divs?
Fragments are faster and consume less memory because it did not create an extra DOM node.
The DOM Inspector is less cluttered.
Some CSS styling like CSS Grid and Flexbox have a special parent-child relationship and add <div> tags in the middle, which makes it hard to keep the desired layout.
Q64. How to apply validation on props in React?
Props validation is a tool which helps the developers to avoid future bugs and problems. React components used special property PropTypes that help you to catch bugs by validating data types of values passed through props, although it is not necessary to define components with propTypes. It makes your code more readable.
We can apply validation on props using App.propTypes in React component. After specifying the validation patterns, you need to set the App.defaultProps. When some of the props are passed with an invalid type, you will get the warnings on JavaScript console.
Q65. What are the differences between class and functional components?
Class Components
Functional Components
Complex as compared to the stateless component.
Simple and easy to understand.
Can hold or manage state.
Cannot hold or manage state.
Can be reused.
Cannot be reused.
Can work with all lifecycle methods.
Does not work with any lifecycle method.
Q66. What is prop drilling?
Anyone who has worked in React would have faced this and if not then will face it definitely. Prop drilling is basically a situation when the same data is being sent at almost every level due to requirements in the final level.
it’s situation where you are passing your props down to 3rd - 4th or Nth level in your components hierarchy.
Q67. Is props read-only?
Yes
Q68. What is event bubbling and event capturing?
Event bubbling is a method when an event is in an element inside another element, is called event bubbling. Means there have parents and child event. When we click on child event then first it hit child and then parent and then onward, it's called event bubbling. In normal way, we use event bubling. And in capturing, its just reverse of event bubling, the event goes top to down element.
We just need to put true or false to convert eact other. If it’s true then Capturing if it’s false then Bubling.
Q69. How to send data from view to action in redux?
With the help of dispatch() [useDispatch] function we can pass data to action.
dispatch() bascically a function that is used to pass data either string, number or object can be send to action.
dispatch(addProductToCart(data));
Q70. What is Redux?
Redux is an open-source JavaScript library for managing and centralizing application state. It is most commonly used with libraries such as React or Angular for building user interfaces. Similar to Facebook's Flux architecture, it was created by Dan Abramov and Andrew Clark.
In short, Redux is a way to manage the "state" or we can say it is a cache or storage that can be accessed by all components with a structured way. It has to be accessed through a "Reducer" and "Actions".
While it’s mostly used as a state management tool with React, you can use it with any other JavaScript framework or library. It’s lightweight at 2KB (including dependencies), so you don’t have to worry about it making your application’s asset size bigger.
npm install --save redux
Q71. When to use Redux?
Redux allows you to manage your app’s state in a single place and keep changes in your app more predictable and traceable. It makes it easier to reason about changes occurring in your app.
Benefits of Redux:
Centralization
Predictability
Time-Travel Debugging
some scenarios when Redux might be the best solution:
When multiple components need to access the same application state
When application state is updated frequently
When you’re working on a large application with several other people
Q72. When not to choose Redux?
Applications that consist of mostly simple UI changes most often don’t require a complicated pattern like Redux. Sometimes, old-fashioned state sharing between different components works as well and improves the maintainability of your code.
Also, you can avoid using Redux if your data comes from a single data source per view. In other words, if you don’t require data from multiple sources, there’s no need to introduce Redux.
Therefore, make sure to check if you need Redux before introducing its complexity.
Q73. How can we get data from Store/Reducer in redux?
With the help of useSelector() method, we can get data from store/reducer. Need to just call state.reducer name. useSelector is a function that takes the current state as an argument and returns whatever data you want from it. It's Allows you to extract data from the Redux store.
Q74. Explain the Lists in React.
Lists are used to display data in an ordered format. In React, Lists can be created in a similar way as we create it in JavaScript. We can traverse the elements of the list using the map() function.
Q75. How are forms created in React?
React offers a stateful, reactive approach to build a form. The forms in React are similar to HTML forms. But in React, the state property of the component is only updated via setState(), and a JavaScript function handles their submission. This function has full access to the data which is entered by the user into a form.
Q76. What is React Router?
React Router is a routing library built on top of React, which is used to create routes in a React application.
It maintains consistent structure and behavior and is used to develop single-page web applications.
Enables multiple views in a single application by defining multiple routes in the React application.
Q77. How is React routing different from normal routing?
React Routing
Normal Routing
The user navigates multiple views in the same file.
The user navigates multiple files for each view.
Single HTML page.
Each view is a new HTML file.
Improved performance.
Slower performance.
The page does not refresh since it is a single file.
The page refreshes every time user navigates.
Q78. How do you modularize code in React?
We can modularize code by using the export and import properties. They help in writing the components separately in different files.
Q79. What do you understand by "Single source of truth"?
Redux uses ‘Store’ for storing the application’s entire state at one place. So all the component’s state are stored in the Store and they receive updates from the Store itself. The single state tree makes it easier to keep track of changes over time and debug or inspect the application.
Hence this concept is called the Single source of truth.
Q80. What are the advantages of Redux?
Predictability of outcome
Community and ecosystem
Maintainability
Developer tools
Server-side rendering
Organization
Ease of testing
Q81. How do you style React components?
Inline Styling
JavaScript Object
CSS Stylesheet
Q82. What is create-react-app?
Create React App is a tool to build React applications. It provides you to create single-page React applications. The create-react-app are preconfigured, which saves you from time-consuming setup and configuration like Webpack or Babel.
It includes a fast, interactive unit test runner with built-in support for coverage reporting.
It includes Autoprefixed CSS, so you don't need -webkit- or other prefixes.
It includes a build script to bundle JS, CSS, and images for production, with hashes and source maps.
It includes a live development server that warns about common mistakes.
It includes React, JSX, ES6, and Flow syntax support.
npx create-react-app my-app
Q83. What are the differences between npm and npx?
NPM
NPX
Npm is a tool that use to install packages.
Npm is a tool that use to install packages.
Packages used by npm are installed globally.
Packages used by npx are not installed globally.
To use create-react-app in npm the commands are npm install create-react-app then create-react-app.
In npx you can use that without installing like npx create-react-app.
Q84. When do we prefer to use a class component over a function component?
If a component needs state or lifecycle methods, we should use the class component, otherwise, use the function component
Q85. What are Forward Refs?
Ref forwarding is a feature which is used for passing a ref through a component to one of its child components. It can be performed by making use of the React.forwardRef() method. It is particularly useful with higher-order components and specially used in reusable component libraries.
Q86. Which is the preferred option callback refs or findDOMNode()?
The preferred option is to use callback refs over findDOMNode() API. Because callback refs give better control when the refs are set and unset whereas findDOMNode() prevents certain improvements in React in the future.
Q87. What is serviceWorker?
You may not need a service worker for your application. If you are creating a project with create-react-app it is invoked by default. A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don't need a web page or user interaction. They already include features like push notifications and background sync and have ability to intercept and handle network requests
Q88. What are hooks in React?
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.Hooks are the functions which "hook into" React state and lifecycle features from function components. It does not work inside classes.
Hooks are backward-compatible, which means it does not contain any breaking changes. Also, it does not replace your knowledge of React concepts.
import React, { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
Q90. What is an error boundary or error boundaries?
An error boundary is a concept introduced in version 16 of React. Error boundaries provide a way to find out the errors that occur in the render phase. Any component which uses one of the following lifecycle methods is considered an error boundary.
Render phase
Inside a lifecycle method
Inside the constructor
Q91. In which cases do error boundaries not catch errors?
Asynchronous code using setTimeout or requestAnimationFrame callbacks.
In the case when errors are thrown in the error boundary code itself.
During the server-side rendering.
Error boundaries don't catch errors inside the event handlers.
Q92. What were the major problems with MVC framework?
It makes the application debugging hard.
It makes the application slow and inefficient.
DOM manipulation was very expensive.
There was a huge memory wastage.
Q93. How to access the Redux store outside a component?
You need to export the Store from the module where it created with createStore() method.
store = createStore(myReducer)
export default store
Q94. Why should we not update the state directly?
If you try to update the state directly then it won't re-render the component.
// Wrong way
this.state.message = 'Programming Path'
Instead use setState() method. It schedules an update to a component's state object.
// Correct way
this.setState({ message: 'Programming Path' })
Q95. What are inline conditional expressions?
You can use either if statements or ternary expressions which are available from JS to conditionally render expressions. Apart from these approaches, you can also embed any expressions in JSX by wrapping them in curly braces.
Q96. What is React Fiber?
Fiber is the new reconciliation engine or reimplementation of core algorithm in React v16. The goal of React Fiber is to increase its suitability for areas like animation, layout, gestures, ability to pause, abort, or reuse work and assign priority to different types of updates and new concurrency primitives.
Q97. How do you memoize a component?
There are memoize libraries available which can be used on function components.
For example moize library can memoize the component in another component.
import moize from 'moize'
import Component from './components/Component' // this module exports a non-memoized component
const MemoizedFoo = moize.react(Component)
const Consumer = () => {
{'I will memoize the following entry:'}
}
Q98. How you implement Server Side Rendering or SSR?
React is already equipped to handle rendering on Node servers. A special version of the DOM renderer is available, which follows the same pattern as on the client side.
import ReactDOMServer from 'react-dom/server'
import App from './App'
ReactDOMServer.renderToString(<App />)
Q99. Do Hooks replace render props and higher order components?
Both render props and higher-order components render only a single child but in most of the cases Hooks are a simpler way to serve this by reducing nesting in your tree.
Q100. What is redux-saga?
redux-saga is a library that aims to make side effects (asynchronous things like data fetching and accessing the browser cache) in Redux applications easier and better.
Q101. What is React lazy function?
The React.lazy function lets you render a dynamic import as a regular component.
It will automatically load the bundle containing the OtherComponent when the component gets rendered.
React.Suspense enables you to specify the loading indicator in the event that the components in the tree below it are not yet ready to render.
Cookie Policy
This website uses cookie or similar technologies, to enhance your browsing experience and provide personalised recommendations. By continuing to use our website, you agree to our Cookie Policy.