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 can I make an AJAX call?

You can use with React JS a  library, like jQuery AJAX.

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

This technology is being used by default but is optional.

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 Children?

In JSX expressions that contain both an opening tag and a closing tag, the content between those tags is passed to components automatically as a special prop: props.children.

There are a number of methods available in the React API to work with this prop. These include React.Children.map, React.Children.forEach, React.Children.count, React.Children