How to debug your React Native app?

  • Use console.log() statements
  • Use the React Native Debugger tool
  • Use the Chrome DevTools
  • There is no way to debug React Native apps
To debug your React Native app, you can use the React Native Debugger tool. This is a standalone debugging tool that provides a range of features for debugging React Native apps, including console logging, breakpoints, and network inspection. The React Native Debugger tool can be used with both iOS and Android devices and emulators.

What is React PropType array with shape?

  • A way to validate a string with a specific shape
  • A way to validate an array of objects with a specific shape
  • A way to validate an array of values with a specific shape
  • A way to validate an object with a specific shape
The "shape" propType in React allows you to validate an object with a specific shape, while the "arrayOf" propType allows you to validate an array of values. The "arrayOf" propType can be combined with the "shape" propType to validate an array of objects with a specific shape. This is useful for validating data structures in React components.

Why we need to pass a function to setState()?

  • To avoid infinite loops
  • To ensure proper synchronization of state updates
  • To handle errors gracefully
  • To improve performance
In React, we need to pass a function to the "setState" method in order to avoid infinite loops. If we pass an object directly, it can cause the component to re-render and update the state endlessly. By passing a function, we can ensure that the state is updated correctly and avoid these issues.

What are hooks?

  • Functions that let you "hook into" React state and lifecycle features from functional components
  • Functions that let you modify the DOM directly from React components
  • Functions that let you render custom elements in React
  • Functions that let you create reusable UI components in React
Hooks are functions that allow developers to "hook into" React state and lifecycle features from functional components. This means that functional components can now have state and lifecycle methods, making them more powerful and flexible. Hooks were introduced in React 16.8 and have since become a popular way of managing state and adding behavior to functional components.

How do you pass arguments to an event handler?

  • By using the event object
  • By using arrow functions
  • By using the bind() method
  • By using the apply() method
In React, arguments can be passed to an event handler by using arrow functions. Arrow functions allow parameters to be passed to the function when it is called, rather than when it is defined. This allows event handlers to receive arguments without causing unnecessary re-renders.

What is the difference between createElement and cloneElement?

  • There is no difference
  • createElement is a class method, while cloneElement is an instance method
  • createElement is used to clone existing elements, while cloneElement is used to create new elements
  • createElement is used to create new DOM elements, while cloneElement is used to clone existing elements
createElement is a method used to create new React elements, while cloneElement is a method used to clone existing React elements and pass new props to the cloned element.

What are stateless components?

  • Components that are only used for layout
  • Components that don't have any children
  • Components that don't have any props
  • Components that don't use any state
Stateless components, also known as functional components, are components that don't use any state. Stateless components are simpler and easier to test than stateful components, but they can't be used for more complex UI components that need to maintain state.

What is ReactDOMServer?

  • A way to create dynamic forms in React components
  • A way to handle routing in React components
  • A way to manage state in React components
  • A way to render React components on the server
ReactDOMServer is a module that allows you to render React components on the server. ReactDOMServer provides several methods for rendering components, including the renderToString method and the renderToStaticMarkup method.

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.