Question:- Which is the preferred option callback refs or findDOMNode()?
Answer:- The preferred option is to use callback refs over findDOMNode() API. Because callback refs give better control when the refs are set and unset whereas findDOMNode() prevents certain improvements in React in the future.
Question:- What is the use of Refs?
Answer:- The Ref in React is used in the following cases: It is used to return a reference to the element. It is used when we need DOM measurements such as managing focus, text selection, or media playback. It is used in triggering imperative animations. It is used when integrating with third-party DOM libraries. It can also use as in callbacks.
Question:- What is React Router?
Answer:- React Router is a standard routing library system built on top of the React. It is used to create Routing in the React application using React Router Package. It helps you to define multiple routes in the app. It provides the synchronous URL on the browser with data that will be displayed on the web page. It maintains the standard structure and behavior of the application and mainly used for developing single page web applications.
Question:- Why do we need a Router in React?
Answer:- React Router plays an important role to display multiple views in a single page application. It is used to define multiple routes in the app. When a user types a specific URL into the browser, and if this URL path matches any route inside the router file, the user will be redirected to that particular Route. So, we need to add a Router library to the React app, which allows creating multiple routes with each leading to us a unique view.
Question:- List down the advantages of React Router.
Answer:- The important advantages of React Router are given below: - In this, it is not necessary to set the browser history manually. - Link uses to navigate the internal links in the application. It is similar to the anchor tag. - It uses Switch feature for rendering. - The Router needs only a Single Child element. - In this, every component is specified in . - The packages are split into three packages, which are Web, Native, and Core. It supports the compact size of the React application.
Question:- Why switch keyword used in React Router v4?
Answer:- The switch keyword is used to display only a single Route to rendered amongst the several defined Routes. The component is used to render components only when the path will be matched. Otherwise, it returns to the not found component.
Question:- How to use styles in React?
Answer:- We can use style attribute for styling in React applications, which adds dynamically-computed styles at render time. It accepts a JavaScript object in camelCased properties rather than a CSS string. The style attribute is consistent with accessing the properties on DOM nodes in JavaScript.
Question:- How many ways can we style the React Component?
Answer:- We can style React Component in mainly four ways, which are given below: - Inline Styling - CSS Stylesheet - CSS Module - Styled Components
Question:- Explain CSS Module styling in React.
Answer:- CSS Module is a CSS file where all class names and animation names are scoped locally by default. It is available only for the component which imports it, and without your permission, it cannot be applied to any other Components. You can create CSS Module file with the .module.css extension.
Question:- What are Styled Components?
Answer:- Styled-Components is a library for React. It is the successor of CSS Modules. It uses enhance CSS for styling React component systems in your application, which is written with a mixture of JavaScript and CSS. It is scoped to a single component and cannot leak to any other element in the page. The styled-components provides: - Automatic critical CSS - No class name bugs - Easier deletion of CSS - Simple dynamic styling - Painless maintenance
Question:- What are hooks in React?
Answer:- Hooks are the new feature introduced in React 16.8 version that facilitates us to use state and other React features without writing a class.
Question:- What are the rules you should follow for the hooks in React?
Answer:- We have to follow the following two rules to use hooks in React: - You should call hooks only at the top level of your React functions and not inside the loops, conditions, or nested functions. This is used to ensure that hooks are called in the same order each time a component renders, and it also preserves the state of hooks between multiple useState and useEffect calls. - You should call hooks from React functions only. Dont call hooks from regular JavaScript functions.
Question:- What are forms in React?
Answer:- In React, forms are used to enable users to interact with web applications. Following is a list of the most common usage of forms in React: - Forms facilitate users to interact with the application. By using forms, the users can communicate with the application and enter the required information whenever required. - Forms contain certain elements, such as text fields, buttons, checkboxes, radio buttons, etc., that can make the application more interactive and beautiful. - Forms are the best possible way to take inputs from the users. - Forms are used for many different tasks such as user authentication, searching, filtering, indexing, etc.
Question:- What is an error boundary or error boundaries?
Answer:- An error boundary is a concept introduced in version 16 of React. Error boundaries provide a way to find out the errors that occur in the render phase. Any component which uses one of the following lifecycle methods is considered an error boundary. Lets see the places where an error boundary can detect an error: - Render phase - Inside a lifecycle method - Inside the constructor
