React JS Interview Questions and Answers Set 10

91.What is the difference between npm & npx?

npm: a node package manager

npx: an npm package runner

92.Difference between constructor and getInitialState ?

The difference between constructor and getInitialState is the difference between ES6 and ES5 itself.

getInitialState is used with React.createClass and constructor is used with React.Component.

ES5

var MyComponent = React.createClass({
getInitialState() {
return { /* initial state */ };
},
});

ES6

class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = { /* initial state */ };
}
}

93.What is the difference between super() and super(props)?

When you want to access this.props inside the constructor then you need to pass the props parameter in super keyword.

94.How does rendering work in React?

Rendering is an important aspect of React as every single component must be rendered. This is done using the render() function. Once the function is called, it returns an element that represents a DOM component.
It is also possible to render more than one HTML element at a time by enclosing the HTML tags and passing them through the render function.

95.Do you need to use ES6 (+) with React? 

This technology is being used by default but is optional.

REACT JS & CERTIFICATION
Weekend / Weekday Batch

96.What a setState  is doing?

It is scheduling a components state object update. If state changes, the component re-renders.

97.What is the difference between a function in setState or passing an object? 

Passing an update function can allow a user to get access to the current state value inside the updater.  As long as setState calls are being batched it may let you complete chain updates and make sure they are being built on the top of each other without any conflict.

98.Explain what is CSS-in-JS pattern? 

CSS-in-JS is a pattern, where CSS is being composed by means of JavaScript instead of being defined in external files. This pattern is not a part of React and is being provided by other libraries because React has no attitude on how to define styles.

99.Can a developer create animations in React? 

No doubt, ReactJS can be easily used for powering animations.

100.What is a higher-order component in React?

Higher-order components (HOCs) are a widely used technique in React for applying concepts that involve the component reusability logic. They are not a React Native Firebase part of the React API and allow users to easily reuse the code and bootstrap abstraction.
HOCs are also used to allow simple sharing of behaviors across all of the components in React, adding more advances to the efficiency and functioning of the application.