What rules need to be followed for hooks?

  • Hooks can only be used in functional components
  • Hooks must be called in the same order on every render
  • Hooks cannot be used with class components
  • Hooks must be called at the beginning of a component's render method
The rules for using hooks in React include calling hooks in the same order on every render and not calling hooks inside loops, conditions, or nested functions. Additionally, hooks can only be used in functional components or custom hooks, not in class components.

What is the use of the ownProps parameter in mapStateToProps() and mapDispatchToProps()?

  • It provides access to the Redux store's state
  • It provides access to the component's own props
  • It provides access to the dispatch function
The ownProps parameter in mapStateToProps() and mapDispatchToProps() provides access to the component's own props. This can be useful when you need to use a prop value to compute a new prop value or when you need to pass a prop to an action creator.

What is the proper placement for error boundaries?

  • They should be placed at the top level of the component tree
  • They should be placed in every component that renders other components
  • They should be placed in the root element of the application
  • They can be placed anywhere in the component tree
Error boundaries in React should be placed at the top level of the component tree, as close to the root of the application as possible. This ensures that errors are caught and handled as early as possible in the rendering process, and prevents them from affecting other components or causing cascading errors.

What is the methods order when component re-rendered?

  • constructor(), render(), componentDidMount()
  • render(), componentDidUpdate(), componentWillUnmount()
  • render(), componentDidUpdate(), componentDidMount()
  • componentDidMount(), render(), componentDidUpdate()
When a component is re-rendered in React, the order of methods that are called is as follows: render(), componentDidUpdate(), and then componentDidMount(). The render() method is called to update the component's UI based on any changes in props or state, followed by componentDidUpdate() to handle any side effects that may have occurred as a result of the update. Finally, componentDidMount() is called to perform any additional setup that may be necessary for the updated component.

What is the typical use case of portals?

  • For rendering large lists
  • For creating modals and tooltips
  • For building layouts and grids
  • For handling state in complex components
Portals in React are a way to render a child component outside of its parent component. This is useful in cases where you need to render a child component in a different part of the DOM hierarchy, such as when creating modals or tooltips.

How do you say that state updates are merged?

  • By using setState()
  • By using forceUpdate()
  • By using Object.assign()
  • By using the spread operator
In React, state updates are merged with the existing state using the spread operator. When setState() is called, React updates the state object by merging the new state object with the existing state object. This allows components to update specific properties of the state object without overwriting the entire object.

How to create components in React?

  • Using React.createElement or JSX
  • Using a third-party library
  • Using jQuery
  • Using plain HTML
In React, components can be created using the React.createElement method or JSX syntax. React.createElement is a lower-level API for creating components, while JSX is a syntax extension that allows developers to write HTML-like code in JavaScript. 

What will happen if you use setState in constructor?

  • It will cause a memory leak
  • It will cause an error
  • It will update the component state
  • Nothing
If you use setState in a component's constructor, it will update the component's state. However, this is generally not recommended, as it can cause problems with initialization and lead to confusing code. It is better to set the initial state in the constructor using the this.state property.

What is Redux?

  • A design pattern for managing state in React applications
  • A testing framework for React
  • A CSS preprocessor
  • A database management system
Redux is a design pattern and library for managing state in JavaScript applications, including React. It emphasizes a single source of truth for application state and a unidirectional data flow. Redux allows developers to manage complex state in large applications, and is often used in combination with React.

What is the difference between state and props?

  • Props are internal to a component, while state is external
  • State is managed within a component, while props are passed down from a parent component
  • State is read-only, while props can be changed by the child component
  • There is no difference
The main difference between state and props in React is that state is managed within a component, while props are passed down from a parent component. State is used to manage a component's internal data, which can change over time, while props are used to customize a component's behavior and appearance.

What is the difference between component and container in React Redux?

  • Components are stateful, while containers are stateless
  • Components are connected to the Redux store, while containers are not
  • Components are responsible for rendering, while containers are responsible for state management
Components and containers in React Redux have different responsibilities. Components are responsible for rendering UI elements and receive props from their parent components, while containers are connected to the Redux store and manage the application state.

What is Flow?

  • A JavaScript testing framework
  • A state management library
  • A type checking tool for JavaScript
  • A styling library for React
Flow is a type checking tool for JavaScript that is commonly used in React and React Native applications. Flow allows you to add static types to your JavaScript code, which can help to catch errors at compile-time instead of at runtime. Flow is particularly useful in large codebases where it can be difficult to keep track of all the variables and function calls.