What would be the common mistake of function being called every time the component renders?

  • Declaring the function inside the component's render method
  • Not using React.lazy() to lazy-load the component
  • Not using React.memo() to memoize the component
  • Not using the shouldComponentUpdate() method to prevent unnecessary re-renders
A common mistake that can cause a function to be called every time the component renders is declaring the function inside the component's render method. This can cause the function to be recreated every time the component renders, even if the function's dependencies have not changed. To avoid this problem, functions should be declared outside the render method, or in a separate file if they are reused across multiple components.

Should I keep all component's state in Redux store?

  • Yes, it is recommended to keep all component state in the Redux store
  • No, it is recommended to keep only the necessary state in the Redux store
It is not recommended to keep all component state in the Redux store. While Redux is useful for managing state in large applications, it can also add unnecessary complexity and boilerplate code to small applications. It is recommended to keep only the necessary state in the Redux store and use component state for simpler state management needs.

What is the recommended approach of removing an array element in react state?

  • Use the filter() method
  • Use the map() method
  • Use the slice() method
  • Use the splice() method
In React, the recommended approach for removing an element from an array in state is to use the "filter()" method. This allows you to create a new array that contains all the elements of the original array except the one you want to remove. This is a safer and more efficient approach than using the "splice()" method, which mutates the original array and can cause unexpected side effects.

What is code-splitting?

  • A technique for optimizing React component performance
  • A way to split code into smaller, more manageable chunks
  • A method for separating HTML and CSS in a web application
  • A feature of React that enables components to be reused in multiple contexts
Code-splitting is a technique for splitting a large JavaScript bundle into smaller, more manageable chunks. This can improve the performance and load time of a web application by reducing the amount of code that needs to be downloaded and parsed by the browser. In React, code-splitting can be achieved using the dynamic import() method, which allows components to be loaded asynchronously at runtime.

How to use TypeScript in create-react-app application?

  • Use the --typescript flag when creating the app
  • Add the typescript dependency and update the configuration files
  • Use the create-react-app-ts tool instead of create-react-app
To use TypeScript in a create-react-app application, you need to add the typescript dependency and update the configuration files. You can do this manually or by using a tool like react-scripts-ts. After installing the typescript dependency, you need to rename some files and update the configuration files to use TypeScript instead of JavaScript.

What is the purpose of getDerivedStateFromProps() lifecycle method?

  • To fetch data from an API
  • To handle events
  • To update the props based on state changes
  • To update the state based on props changes
The "getDerivedStateFromProps" lifecycle method in React is used to update the state based on changes to props. This method is called every time the component is updated and can return a new state object. It is commonly used to synchronize the state with the props in response to user input or server-side changes.

How to re-render the view when the browser is resized?

  • Use a media query and conditional rendering
  • Use a ref and measure the size of the container element
  • Use a state variable and update it on resize
  • Use a window event listener and call forceUpdate()
In React, you can re-render the view when the browser is resized by using a state variable and updating it on resize. This will trigger a re-render of the component, and allow you to update the layout or other properties based on the new size of the browser window. You can use the "window.addEventListener" method to listen for the "resize" event, and update the state variable accordingly.

What is react-scripts?

  • A build tool for React applications
  • A testing framework for React applications
  • A code analysis tool for React applications
  • A runtime environment for React applications
react-scripts is a build tool that comes bundled with Create React App, a popular tool for creating React applications. react-scripts provides a set of preconfigured build scripts and development tools, such as Webpack and Babel, to simplify the process of setting up and running a React application.

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 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.