What are synthetic events in React?

  • Events that are cross-browser compatible and behave consistently across different platforms
  • Events that are not optimized for performance
  • Events that occur in a virtual environment
  • Events that trigger multiple times
Synthetic events in React are events that are cross-browser compatible and behave consistently across different platforms. They are also optimized for performance by pooling event objects, which allows them to be reused and prevents excessive memory allocation. Synthetic events have the same interface as native events, but they are implemented differently behind the scenes.

Why should not call setState in componentWillUnmount?

  • Because it will cause a memory leak
  • Because it will trigger a re-render after the component is unmounted
  • Because the component's state is no longer available after unmounting
  • Because it is unnecessary and can cause performance issues
The componentWillUnmount() method is called immediately before a component is unmounted and destroyed. It is not safe to call setState() within this method, as the component's state is no longer available after unmounting. Attempting to update the state after unmounting can cause errors or unexpected behavior in the application.

What is the purpose of displayName class property?

  • To set the name of the component's file
  • To set the name of the component for debugging purposes
  • To specify the component's DOM display style
  • To set the component's initial state
The displayName class property in a React component is used to set the name of the component for debugging purposes. This name is used in error messages and in the React Developer Tools to help identify the component in the component hierarchy. If the displayName property is not set explicitly, React will attempt to infer the name of the component from the name of the component class or function.

What is state in React?

  • A component's HTML markup
  • A component's internal data
  • A component's lifecycle methods
  • A component's properties
In React, state refers to a component's internal data that can change over time. State is managed using the setState method, which allows developers to update the state of a component and trigger a re-render of the UI. State is used to keep track of data that changes in response to user input or other events.

Is it good to use arrow functions in render methods?

  • Yes, it improves performance
  • No, it can cause unnecessary re-renders
  • It depends on the use case
  • It has no effect on performance
It is not recommended to use arrow functions in render methods because it can cause unnecessary re-renders. Arrow functions are created each time the component renders, which can cause a new reference to be passed down to child components, triggering unnecessary re-renders.

Is it a must that the prop must be named as "render" for render props?

  • Yes, it is a strict requirement
  • No, it can be named anything
Render props in React are a technique for sharing code between components. A render prop is a function that a component uses to render its children, allowing the children to access the component's state or other data. The render prop can be named anything, and the name of the prop does not affect its functionality. The convention of naming the prop "render" is simply a convention and is not required by React.

What is reselect and how it works?

  • A middleware for handling asynchronous actions in Redux
  • A library for managing forms in Redux applications
  • A tool for debugging React Native applications
  • A library for optimizing Redux selectors
Reselect is a library for optimizing Redux selectors. It provides a way to create memoized selectors that only recompute when their input selectors have changed. This can help to improve performance and reduce unnecessary re-renders in React applications. Reselect works by caching the results of previous computations and only re-executing the computation if the input selectors have changed.

What is the purpose of callback function as an argument of setState()?

  • To handle errors
  • To improve performance
  • To synchronize state updates
  • To update the state asynchronously
The callback function as an argument of the setState method in React is used to update the state asynchronously. When the setState method is called, the state update may not happen immediately, which can cause issues when trying to access the updated state. The callback function is called after the state has been updated, ensuring that the updated state is available for use.

What will happen if you use props in initial state?

  • It will cause a memory leak
  • It will cause a runtime error
  • It will ignore the props
  • It will work as expected
Using props in initial state will cause the initial state to ignore the props. This is because the initial state is only set once, when the component is first created. If you want to use props to initialize state, you should set the state in the constructor instead.

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.