What are the sources used for introducing hooks?

  • Community proposals and discussions
  • Official React documentation and blog posts
  • React conferences and meetups
  • All of the above
React Hooks were introduced based on community proposals and discussions, as well as official React documentation and blog posts. They were also presented and discussed at React conferences and meetups.

What are portals in React?

  • A way to communicate between components
  • A way to create dynamic forms
  • A way to handle errors in components
  • A way to render a component's children in a different part of the DOM
Portals in React provide a way to render a component's children in a different part of the DOM. This can be useful for creating modal dialogs, tooltips, and other UI components that need to be positioned outside the normal flow of the page.

What is the difference between Element and Component?

  • Element is a React class, while Component is a React function
  • Element is a plain JavaScript object, while Component is a function or class that returns an Element
  • Element represents a single HTML element, while Component can represent multiple HTML elements
  • There is no difference
In React, an element is a plain JavaScript object that represents a single HTML element. A component, on the other hand, is a function or class that returns an element (or multiple elements). Components are used to create reusable UI elements, while elements are used to represent the actual DOM elements that make up the UI.

How do you programmatically navigate using React router v4?

  • Use the "document.navigate" function with a URL string
  • Use the "this.props.history.push" method with a route path
  • Use the "this.props.navigate" method with a route path
  • Use the "window.location" object with a URL string
In React Router v4, you can programmatically navigate by using the "history" object provided by the router. To navigate to a new route, you can use the "this.props.history.push" method with a route path as a string. This method adds a new entry to the history stack and navigates to the specified route. For example: this.props.history.push('/new-route');.

How to use https instead of http in create-react-app?

  • Use the HTTP=false environment variable
  • Use the HTTPS=true environment variable
  • Use the SSL=true environment variable
  • Use the SSL_CERTIFICATE=true environment variable
In Create React App, you can use HTTPS instead of HTTP by setting the "HTTPS=true" environment variable. This will start the development server with HTTPS enabled, and will allow you to test your application with SSL/TLS encryption.

What is the difference between setState and replaceState methods?

  • There is no difference, they both update component state
  • replaceState is deprecated in React v16, while setState is still supported
  • setState is used in class components, while replaceState is used in functional components
  • setState merges the new state with the old state, while replaceState overwrites the old state
In React, the "setState" method is used to update component state, and it merges the new state with the old state. The "replaceState" method is similar, but it overwrites the old state completely with the new state. However, "replaceState" is deprecated in React and should not be used. Instead, you should use the "setState" method to update state in a React component.

Is the ref argument available for all functions or class components?

  • Yes, for all components
  • No, only for class components
  • No, only for function components
The ref argument is only available for class components in React. Function components do not have an instance, so refs cannot be attached to them. Refs can be attached to DOM elements, class components, and functional components that are created using the forwardRef() method.

Do I need to keep all my state into Redux? Should I ever use react internal state?

  • Yes, you should always use Redux to manage all of your application state
  • No, you should never use Redux and always use React internal state
  • It depends on the complexity and size of your application
  • It depends on whether you are using class or functional components
Whether or not to use Redux to manage state in a React application depends on the complexity and size of the application. For small and simple applications, it may be sufficient to use React's internal state management. However, for larger and more complex applications, Redux can be a helpful tool for managing application state.

What are stateful components?

  • Components that are only used for layout
  • Components that don't use any state
  • Components that maintain state
  • Components that only have props
Stateful components, also known as class components, are components that maintain state. Stateful components are useful for creating more complex UI components that need to maintain state, but they are more difficult to test than stateless components.

How to get query parameters in React Router v4

  • Use the "this.props.location.query" object
  • Use the "this.props.location.search" property
  • Use the "this.props.params" object
  • Use the "this.props.query" object
In React Router v4, you can get query parameters by using the "location.search" property of the current location object. This property contains the query string of the URL, including the "?" character and the parameter keys and values. To parse the query string, you can use a library like "query-string" or "URLSearchParams". For example: const queryParams = new URLSearchParams(this.props.location.search); const foo = queryParams.get('foo');.

What is React lazy function?

  • A function that creates a lazy version of a component
  • A function that returns a higher-order component
  • A function that creates a new instance of a component
  • A function that creates a new element in the DOM
React lazy is a function that creates a lazy version of a component. This lazy version is loaded only when it is actually needed, such as when a user navigates to a page that requires the component. This can help improve performance by reducing the initial load time of the application.

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.