Why are String Refs legacy?

  • They are no longer needed with the introduction of functional components
  • They are not supported in modern browsers
  • They are slow and inefficient
  • They can cause naming conflicts and bugs
String refs, which allow developers to set refs using a string identifier, are considered legacy because they can cause naming conflicts and bugs. They have been replaced with callback refs and the React.createRef() API.

What is the difference between Shadow DOM and Virtual DOM?

  • Shadow DOM is a browser feature, while Virtual DOM is a React feature
  • Shadow DOM is used for server-side rendering, while Virtual DOM is used for client-side rendering
  • Shadow DOM is used for styling and encapsulation, while Virtual DOM is used for performance optimization
  • There is no difference
Shadow DOM and Virtual DOM are two different concepts. Shadow DOM is a browser feature that allows developers to encapsulate styles and markup within components. Virtual DOM, on the other hand, is a React feature that allows for performance optimization by minimizing changes to the actual DOM.

Why should we not update the state directly?

  • It can cause memory leaks
  • It can cause race conditions
  • It can cause the application to crash
  • It can cause the component to re-render
In React, state should not be updated directly because it can cause the component to re-render improperly. Instead, the setState method should be used to update state, which triggers a re-render of the component and ensures that the updated state is properly reflected in the UI.

What are fragments?

  • A way to create custom HTML elements
  • A way to group multiple elements without adding an extra DOM node
  • An alternative to using HTML tags for styling
  • Special React components
Fragments are a way to group multiple elements without adding an extra DOM node. Fragments are useful when you want to return multiple elements from a component, but don't want to add an unnecessary container element to the DOM.

How events are different in React?

  • All the options
  • Events in React are synthetic events
  • React events are camelCase instead of lowercase
  • React events have a different API than native events
Events in React are different from native events in several ways. React events are synthetic events that are cross-browser compatible and have the same API across all browsers. React events are also camelCase instead of lowercase (e.g. onClick instead of onclick). Finally, React events have a different API than native events, including the ability to call preventDefault and stopPropagation on the event object.

How to prevent a function from being called multiple times?

  • Use memoization
  • Use shouldComponentUpdate lifecycle method
  • Use componentDidUpdate lifecycle method
  • Use a callback ref
Memoization is a technique used to optimize functions by caching the results of expensive function calls and returning the cached result when the same inputs occur again. By using memoization, a function can be prevented from being called multiple times with the same inputs.

What are error boundaries in React v16?

  • A way to create dynamic forms
  • A way to handle errors in React components
  • A way to optimize rendering performance
  • A way to render components outside the normal DOM
Error boundaries are a way to handle errors in React components. In React v16, error boundaries are special components that catch and handle errors that occur during rendering. This can help prevent the entire application from crashing due to an error in a single component.

Is it recommended to use CSS In JS technique in React?

  • Yes, it is a best practice
  • No, it is not recommended
  • It depends on the project requirements
The decision to use CSS in JS is largely dependent on the specific project requirements and the preferences of the development team. CSS in JS can offer certain benefits, such as better modularity and encapsulation of styles, but it may not be the best choice for every project.

What is Jest?

  • A package for generating test data
  • A tool for simulating component rendering without deep rendering
  • A package for mocking HTTP requests
  • A testing framework for React
Jest is a testing framework for JavaScript applications, including React. It is developed by Facebook and is widely used in the React community. Jest includes features such as snapshot testing, mocking, and code coverage analysis. It can be used to test React components and other JavaScript code.

What is the difference between HTML and React event handling?

  • HTML uses camelCase event names, while React uses kebab-case
  • HTML uses inline event handlers, while React uses event listeners
  • React uses synthetic events, while HTML does not
  • There is no difference
The main difference between HTML and React event handling is that React uses synthetic events, while HTML does not. Synthetic events are cross-browser compatible and behave consistently across different platforms. They are also optimized for performance by pooling event objects.