React js interview questions and answers

Are you going for an interview? Are you applying for React.js developer? We have some interview questions that will surely help you with your interview.

These questions are related to core functionality of React.js. But these will also be helpful if you’re looking for react native interview questions.

Q1. How does React work?

React provides a component based UI designing methodology. You create small components which can be reused. React creates a virtual DOM from those components. It is a tree structure where parents have many children. When any change occur in the state of any component, it calculates the changes needed to be done in all other components and performs the updates by calling the render function for those components if necessary.

Q2. How does render function work ?

Render function is called every time when state is updated inside a component by default. Render function is bound to setState() function. Whenever you update your state using setState(), it will re-render your component as soon as possible.

However rerendering of component can be interrupted as it is based on the output of shouldComponentUpdate lifecycle function. If this function is implemented and returns false, render function will not be called. This can be conditionally used to improve peformance.

Q3. What is state and how should you mutate it?

In React.js you have a class level variable named state which holds the current state of your component i.e current values or data of your app. React uses this state object to determine if component needs to be updated.

You can and should mutate your state by calling the setState() function.

Q4. Why do we create components?

We create components to break our UI into smaller parts which can be reused. It improves performance because whenever state is updated React calculate what components should rerender.

Q5. What is state full and stateless component?

State full components are those which created with a proper class structure. They maintain their own state variable.

Stateless components are simple arrow functions or function components which doesn’t maintain a state variable. They however have their own context.

Q6. What is JSX?

JSX is the syntax extension of Javascript. You can combine components with language using it.

We will update this article with more questions in future.

Leave a Reply

Your email address will not be published. Required fields are marked *