Skip to main content

ReactJS

Roadmap

React Roadmap - roadmap.sh

React Interview Questions & Answers

Note: This repository is specific to ReactJS. Please check Javascript Interview questions for core javascript questions.

Table of Contents

No.Questions
Core React
1What is the difference between Element and Component?
2When to use a Class Component over a Function Component?
7What are Pure Components?
8What is state in React?
9What are props in React?
10What is the difference between state and props?
11Why should we not update the state directly?
12What is the purpose of callback function as an argument of setState()?
13What is the difference between HTML and React event handling?
14How to bind methods or event handlers in JSX callbacks?
15How to pass a parameter to an event handler or callback?
16What are synthetic events in React?
17What are inline conditional expressions?
18What is "key" prop and what is the benefit of using it in arrays of elements?
19What is the use of refs?
20How to create refs?
21What are forward refs?
22Which is preferred option with in callback refs and findDOMNode()?
23Why are String Refs legacy?
24What is Virtual DOM?
25How Virtual DOM works?
26What is the difference between Shadow DOM and Virtual DOM?
27What is React Fiber?
28What is the main goal of React Fiber?
29What are controlled components?
30What are uncontrolled components?
31What is the difference between createElement and cloneElement?
32What is Lifting State Up in React?
33What are the different phases of component lifecycle?
34What are the lifecycle methods of React?
35What are Higher-Order components?
36How to create props proxy for HOC component?
37What is context?
38What is children prop?
39How to write comments in React?
40What is the purpose of using super constructor with props argument?
41What is reconciliation?
42How to set state with a dynamic key name?
43What would be the common mistake of function being called every time the component renders?
44Is lazy function supports named exports?
45Why React uses className over class attribute?
46What are fragments?
47Why fragments are better than container divs?
48What are portals in React?
49What are stateless components?
50What are stateful components?
51How to apply validation on props in React?
52What are the advantages of React?
53What are the limitations of React?
54What are error boundaries in React v16
55How error boundaries handled in React v15?
56What are the recommended ways for static type checking?
57What is the use of react-dom package?
58What is the purpose of render method of react-dom?
59What is ReactDOMServer?
60How to use InnerHtml in React?
61How to use styles in React?
62How events are different in React?
63What will happen if you use setState in constructor?
64What is the impact of indexes as keys?
65Is it good to use setState() in componentWillMount() method?
66What will happen if you use props in initial state?
67How do you conditionally render components?
68Why we need to be careful when spreading props on DOM elements??
69How you use decorators in React?
70How do you memoize a component?
71How you implement Server-Side Rendering or SSR?
72How to enable production mode in React?
73What is CRA and its benefits?
74What is the lifecycle methods order in mounting?
75What are the lifecycle methods going to be deprecated in React v16?
76What is the purpose of getDerivedStateFromProps() lifecycle method?
77What is the purpose of getSnapshotBeforeUpdate() lifecycle method?
78Do Hooks replace render props and higher order components?
79What is the recommended way for naming components?
80What is the recommended ordering of methods in component class?
81What is a switching component?
82Why we need to pass a function to setState()?
83What is strict mode in React?
84What are React Mixins?
85Why is isMounted() an anti-pattern and what is the proper solution?
86What are the Pointer Events supported in React?
87Why should component names start with capital letter?
88Are custom DOM attributes supported in React v16?
89What is the difference between constructor and getInitialState?
90Can you force a component to re-render without calling setState?
91What is the difference between super() and super(props) in React using ES6 classes?
92How to loop inside JSX?
93How do you access props in attribute quotes?
94What is React PropType array with shape?
95How to conditionally apply class attributes?
96What is the difference between React and ReactDOM?
97Why ReactDOM is separated from React?
98How to use React label element?
99How to combine multiple inline style objects?
100How to re-render the view when the browser is resized?
101What is the difference between setState and replaceState methods?
102How to listen to state changes?
103What is the recommended approach of removing an array element in react state?
104Is it possible to use React without rendering HTML?
105How to pretty print JSON with React?
106Why you can't update props in React?
107How to focus an input element on page load?
108What are the possible ways of updating objects in state?
110How can we find the version of React at runtime in the browser?
111What are the approaches to include polyfills in your create-react-app?
112How to use https instead of http in create-react-app?
113How to avoid using relative path imports in create-react-app?
114How to add Google Analytics for react-router?
115How to update a component every second?
116How do you apply vendor prefixes to inline styles in React?
117How to import and export components using react and ES6?
118What are the exceptions on React component naming?
119Why is a component constructor called only once?
120How to define constants in React?
121How to programmatically trigger click event in React?
122Is it possible to use async/await in plain React?
123What are the common folder structures for React?
124What are the popular packages for animation?
125What is the benefit of styles modules?
126What are the popular React-specific linters?
127How to make AJAX call and In which component lifecycle methods should I make an AJAX call?
128What are render props?
React Router
129What is React Router?
130How React Router is different from history library?
131What are the Router components of React Router v4?
132What is the purpose of push and replace methods of history?
133How do you programmatically navigate using React router v4?
134How to get query parameters in React Router v4
135Why you get "Router may have only one child element" warning?
136How to pass params to history.push method in React Router v4?
137How to implement default or NotFound page?
138How to get history on React Router v4?
139How to perform automatic redirect after login?
React Internationalization
140What is React-Intl?
141What are the main features of React Intl?
142What are the two ways of formatting in React Intl?
143How to use FormattedMessage as placeholder using React Intl?
144How to access current locale with React Intl
145How to format date using React Intl?
React Testing
146What is Shallow Renderer in React testing?
147What is TestRenderer package in React?
148What is the purpose of ReactTestUtils package?
149What is Jest?
150What are the advantages of Jest over Jasmine?
151Give a simple example of Jest test case
React Redux
152What is Flux?
153What is Redux?
154What are the core principles of Redux?
155What are the downsides of Redux compared to Flux?
156What is the difference between mapStateToProps() and mapDispatchToProps()?
157Can I dispatch an action in reducer?
158How to access Redux store outside a component?
159What are the drawbacks of MVW pattern
160Are there any similarities between Redux and RxJS?
161How to dispatch an action on load?
162How to use connect from React Redux?
163How to reset state in Redux?
164Whats the purpose of at symbol in the redux connect decorator?
165What is the difference between React context and React Redux?
166Why are Redux state functions called reducers?
167How to make AJAX request in Redux?
168Should I keep all component's state in Redux store?
169What is the proper way to access Redux store?
170What is the difference between component and container in React Redux?
171What is the purpose of the constants in Redux?
172What are the different ways to write mapDispatchToProps()?
173What is the use of the ownProps parameter in mapStateToProps() and mapDispatchToProps()?
174How to structure Redux top level directories?
175What is redux-saga?
176What is the mental model of redux-saga?
177What are the differences between call and put in redux-saga
178What is Redux Thunk?
179What are the differences between redux-saga and redux-thunk
180What is Redux DevTools?
181What are the features of Redux DevTools?
182What are Redux selectors and Why to use them?
183What is Redux Form?
184What are the main features of Redux Form?
185How to add multiple middlewares to Redux?
186How to set initial state in Redux?
187How Relay is different from Redux?
188What is an action in Redux?
React supported libraries and Integration
192What is reselect and how it works?
193What is Flow?
194What is the difference between Flow and PropTypes?
195How to use font-awesome icons in React?
196What is React Dev Tools?
197Why is DevTools not loading in Chrome for local files?
198How to use Polymer in React?
199What are the advantages of React over Vue.js?
200What is the difference between React and Angular?
201Why React tab is not showing up in DevTools?
202What are styled components?
203Give an example of Styled Components?
204What is Relay?
205How to use TypeScript in create-react-app application?
Miscellaneous
206What are the main features of reselect library?
207Give an example of reselect usage?
209Does the statics object work with ES6 classes in React?
210Can Redux only be used with React?
211Do you need to have a particular build tool to use Redux?
212How Redux Form initialValues get updated from state?
213How React PropTypes allow different type for one prop?
214Can I import an SVG file as react component?
215Why are inline ref callbacks or functions not recommended?
216What is render hijacking in React?
217What are HOC factory implementations?
218How to pass numbers to React component?
219Do I need to keep all my state into Redux? Should I ever use react internal state?
220What is the purpose of registerServiceWorker in React?
221What is React memo function?
222What is React lazy function?
223How to prevent unnecessary updates using setState?
224How do you render Array, Strings and Numbers in React 16 Version?
225How to use class field declarations syntax in React classes?
226What are hooks?
227What rules need to be followed for hooks?
228How to ensure hooks followed the rules in your project?
229What are the differences between Flux and Redux?
230What are the benefits of React Router V4?
231Can you describe about componentDidCatch lifecycle method signature?
232In which scenarios error boundaries do not catch errors?
233Why do you not need error boundaries for event handlers?
234What is the difference between try catch block and error boundaries?
235What is the behavior of uncaught errors in react 16?
236What is the proper placement for error boundaries?
237What is the benefit of component stack trace from error boundary?
238What is the required method to be defined for a class component?
239What are the possible return types of render method?
240What is the main purpose of constructor?
241Is it mandatory to define constructor for React component?
242What are default props?
243Why should not call setState in componentWillUnmount?
244What is the purpose of getDerivedStateFromError?
245What is the methods order when component re-rendered?
246What are the methods invoked during error handling?
247What is the purpose of displayName class property?
248What is the browser support for react applications?
249What is the purpose of unmountComponentAtNode method?
250What is code-splitting?
251What is the benefit of strict mode?
252What are Keyed Fragments?
253Does React support all HTML attributes?
254What are the limitations with HOCs?
255How to debug forwardRefs in DevTools?
256When component props defaults to true?
257What is NextJS and major features of it?
258How do you pass an event handler to a component?
259Is it good to use arrow functions in render methods?
260How to prevent a function from being called multiple times?
261How JSX prevents Injection Attacks?
262How do you update rendered elements?
263How do you say that props are read only?
264How do you say that state updates are merged?
265How do you pass arguments to an event handler?
266How to prevent component from rendering?
267What are the conditions to safely use the index as a key?
268Is it keys should be globally unique?
269What is the popular choice for form handling?
270What are the advantages of formik over redux form library?
271Why do you not required to use inheritance?
272Can I use web components in react application?
273What is dynamic import?
274What are loadable components?
275What is suspense component?
276What is route based code splitting?
277Give an example on How to use context?
278What is the purpose of default value in context?
279How do you use contextType?
280What is a consumer?
281How do you solve performance corner cases while using context?
282What is the purpose of forward ref in HOCs?
283Is it ref argument available for all functions or class components?
284Why do you need additional care for component libraries while using forward refs?
285How to create react class components without ES6?
286Is it possible to use react without JSX?
287What is diffing algorithm?
288What are the rules covered by diffing algorithm?
289When do you need to use refs?
290Is it prop must be named as render for render props?
291What are the problems of using render props with pure components?
292How do you create HOC using render props?
293What is windowing technique?
294How do you print falsy values in JSX?
295What is the typical use case of portals?
296How do you set default value for uncontrolled component?
297What is your favorite React stack?
298What is the difference between Real DOM and Virtual DOM?
299How to add Bootstrap to a react application?
300Can you list down top websites or applications using react as front end framework?
301Is it recommended to use CSS In JS technique in React?
302Do I need to rewrite all my class components with hooks?
303How to fetch data with React Hooks?
304Is Hooks cover all use cases for classes?
305What is the stable release for hooks support?
306Why do we use array destructuring (square brackets notation) in useState?
307What are the sources used for introducing hooks?
308How do you access imperative API of web components?
309What is formik?
310What are typical middleware choices for handling asynchronous calls in Redux?
311Do browsers understand JSX code?
312Describe about data flow in react?
313What is react scripts?
314What are the features of create react app?
315What is the purpose of renderToNodeStream method?
316What is MobX?
317What are the differences between Redux and MobX?
318Should I learn ES6 before learning ReactJS?
319What is Concurrent Rendering?
320What is the difference between async mode and concurrent mode?
321Can I use javascript urls in react16.9?
322What is the purpose of eslint plugin for hooks?
323What is the difference between Imperative and Declarative in React?
324What are the benefits of using typescript with reactjs?
325How do you make sure that user remains authenticated on page refresh while using Context API State Management?
326What are the benefits of new JSX transform?
327How does new JSX transform different from old transform?
328How do you get redux scaffolding using create-react-app?
329What are React Server components?
330What is prop drilling?
331What is state mutation and how to prevent it?
332What is the difference between useState and useRef hook?

Core React

1. What is the difference between Element and Component?

An Element is a plain object describing what you want to appear on the screen in terms of the DOM nodes or other components. Elements can contain other Elements in their props. Creating a React element is cheap. Once an element is created, it is never mutated.

The object representation of React Element would be as follows:

const element = React.createElement(
'div',
{id: 'login-btn'},
'Login'
)

The above React.createElement() function returns an object:

{
type: 'div',
props: {
children: 'Login',
id: 'login-btn'
}
}

And finally it renders to the DOM using ReactDOM.render():

<div id='login-btn'>Login</div>

Whereas a component can be declared in several different ways. It can be a class with a render() method or it can be defined as a function. In either case, it takes props as an input, and returns a JSX tree as the output:

const Button = ({ onLogin }) =>
<div id={'login-btn'} onClick={onLogin}>Login</div>

Then JSX gets transpiled to a React.createElement() function tree:

const Button = ({ onLogin }) => React.createElement(
'div',
{ id: 'login-btn', onClick: onLogin },
'Login'
)

⬆ Back to Top

2. When to use a Class Component over a Function Component?

If the component needs state or lifecycle methods then use class component otherwise use function component. However, from React 16.8 with the addition of Hooks, you could use state , lifecycle methods and other features that were only available in class component right in your function component. So, it is always recommended to use Function components, unless you need a React functionality whose Function component equivalent is not present yet, like Error Boundaries

⬆ Back to Top