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
Question:- In which cases do error boundaries not catch errors?
Answer:- Following are some cases in which error boundaries dont catch errors: - Error boundaries dont catch errors inside the event handlers. - During the server-side rendering. - In the case when errors are thrown in the error boundary code itself. - Asynchronous code using setTimeout or requestAnimationFrame callbacks
Question:- What were the major problems with MVC framework?
Answer:- The major problems with the MVC framework are: - DOM manipulation was very expensive. - It makes the application slow and inefficient. - There was a huge memory wastage. - It makes the application debugging hard.
Question:- What were the major problems with MVC framework?
Answer:- The major problems with the MVC framework are: - DOM manipulation was very expensive. - It makes the application slow and inefficient. - There was a huge memory wastage. - It makes the application debugging hard.
