Question:- Why we use JSX?
Answer:- - It is faster than regular JavaScript because it performs optimization while translating the code to JavaScript. - Instead of separating technologies by putting markup and logic in separate files, React uses components that contain both. - t is type-safe, and most of the errors can be found at compilation time. - It makes easier to create templates.
Question:- What do you understand by Virtual DOM?
Answer:- 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.
Question:- Explain the working of Virtual DOM.
Answer:- Virtual DOM works in three steps: 1. Whenever any data changes in the React App, the entire UI is re-rendered in Virtual DOM representation. 2. Now, the difference between the previous DOM representation and the new DOM is calculated. 3. Once the calculations are completed, the real DOM updated with only those things which are changed.
Question:- What do you understand from "In React, everything is a component."
Answer:- In React, components are the building blocks of React applications. These components divide the entire React applications UI into small, independent, and reusable pieces of code. React renders each of these components independently without affecting the rest of the application UI. Hence, we can say that, in React, everything is a component.
Question:- What is Props?
Answer:- Props stand for "Properties" in React. They are read-only inputs to components. Props are an object which stores the value of attributes of a tag and work similar to the HTML attributes. It gives a way to pass data from the parent to the child components throughout the application. It is similar to function arguments and passed to the component in the same way as arguments passed in a function. Props are immutable so we cannot modify the props from inside the component. Inside the components, we can add attributes called props. These attributes are available in the component as this.props and can be used to render dynamic data in our render method.
Question:- What is a State in React?
Answer:- The State is an updatable structure which holds the data and information about the component. It may be changed over the lifetime of the component in response to user action or system event. It is the heart of the react component which determines the behavior of the component and how it will render. It must be kept as simple as possible.
Question:- How can you update the State of a component?
Answer:- We can update the State of a component using this.setState() method. This method does not always replace the State immediately. Instead, it only adds changes to the original State. It is a primary method which is used to update the user interface(UI) in response to event handlers and server responses.
Question:- What is arrow function in React? How is it used?
Answer:- The Arrow function is the new feature of the ES6 standard. If you need to use arrow functions, it is not necessary to bind any event to this. Here, the scope of this is global and not limited to any calling function. So If you are using Arrow Function, there is no need to bind this inside the constructor. It is also called fat arrow (=>) functions.
Question:- What is an event in React?
Answer:- An event is an action which triggers as a result of the user action or system generated event like a mouse click, loading of a web page, pressing a key, window resizes, etc. In React, the event handling system is very similar to handling events in DOM elements. The React event handling system is known as Synthetic Event, which is a cross-browser wrapper of the browsers native event. Handling events with React have some syntactical differences, which are: - React events are named as camelCase instead of lowercase. - With JSX, a function is passed as the event handler instead of a string.
Question:- What are synthetic events in React?
Answer:- A synthetic event is an object which acts as a cross-browser wrapper around the browsers native event. It combines the behavior of different browsers native event into one API, including stopPropagation() and preventDefault().
Question:- Explain the Lists in React.
Answer:- 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.
Question:- What is the significance of keys in React?
Answer:- A key is a unique identifier. In React, it is used to identify which items have changed, updated, or deleted from the Lists. It is useful when we dynamically created components or when the users alter the lists. It also helps to determine which components in a collection needs to be re-rendered instead of re-rendering the entire set of components every time. It increases application performance.
Question:- How are forms created in React?
Answer:- Forms allow the users to interact with the application as well as gather information from the users. Forms can perform many tasks such as user authentication, adding user, searching, filtering, etc. A form can contain text fields, buttons, checkbox, radio button, etc. 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.
Question:- What are the different phases of React components lifecycle?
Answer:- The different phases of React components lifecycle are: - Initial Phase: It is the birth phase of the React lifecycle when the component starts its journey on a way to the DOM. In this phase, a component contains the default Props and initial State. These default properties are done in the constructor of a component. - Mounting Phase: In this phase, the instance of a component is created and added into the DOM. - Updating Phase: It is the next phase of the React lifecycle. In this phase, we get new Props and change State. This phase can potentially update and re-render only when a prop or state change occurs. The main aim of this phase is to ensure that the component is displaying the latest version of itself. This phase repeats again and again. - Unmounting Phase: It is the final phase of the React lifecycle, where the component instance is destroyed and unmounted(removed) from the DOM.
