- It is required for each component to have a render() function. This function returns the HTML, which is to be displayed in the component.
- If you need to render more than one element, all of the elements must be inside one parent tag like <div>, <form>.
Category: ReactJS Interview Question
https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQWVFjQ5rCH3w8I5JUGiE_GcKNaE-Wy_loi_w&s
-
What is the use of render() in React?
-
. How do you create forms in React?
We create forms in React by doing the following:
The above code will yield an input field with the label Name and a submit button. It will also alert the user when the submit button is pressed.
-
What are the components in React?
Components are the building blocks of any React application, and a single app usually consists of multiple components. A component is essentially a piece of the user interface. It splits the user interface into independent, reusable parts that can be processed separately.
There are two types of components in React:
- Functional Components: These types of components have no state of their own and only contain render methods, and therefore are also called stateless components. They may derive data from other components as props (properties).
function Greeting(props) { return <h1>Welcome to {props.name}</h1>;} - Class Components: These types of components can hold and manage their own state and have a separate render method to return JSX on the screen. They are also called Stateful components as they can have a state.
class Greeting extends React.Component { render() { return <h1>Welcome to {this.props.name}</h1>; }} -
How is React different from Angular?
Angular React Author Google Facebook Architecture Complete MVC View layer of MVC DOM Real DOM Virtual DOM Data-Binding Bi-directional Uni-directional Rendering Client-Side Server-Side Performance Comparatively slow Faster due to Virtual DOM -
How is React different from React Native?
React React Native Release 2013 2015 Platform Web Mobile – Android, iOS HTML Yes No CSS Yes No Prerequisites JavaScript, HTML, CSS React.js -
What is an arrow function and how is it used in React?
- An arrow function is a short way of writing a function to React.
- It is unnecessary to bind ‘this’ inside the constructor when using an arrow function. This prevents bugs caused by the use of ‘this’ in React callbacks.
-
How do you write comments in React?
There are basically two ways in which we can write comments:
- Single-line comments
- Multi-line comments
-
What are forms in React?
React employs forms to enable users to interact with web applications.
- Using forms, users can interact with the application and enter the required information whenever needed. Form contain certain elements, such as text fields, buttons, checkboxes, radio buttons, etc
- Forms are used for many different tasks such as user authentication, searching, filtering, indexing, etc
-
Why is there a need for using keys in Lists?
Keys are very important in lists for the following reasons:
- A key is a unique identifier and it is used to identify which items have changed, been updated or deleted from the lists
- It also helps to determine which components need to be re-rendered instead of re-rendering all the components every time. Therefore, it increases performance, as only the updated components are re-rendered
-
Explain how lists work in React
- We create lists in React as we do in regular JavaScript. Lists display data in an ordered format
- The traversal of lists is done using the map() function