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.

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');.

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.

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

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 your favorite React stack?

  • MERN (MongoDB, Express, React, Node)
  • MEAN (MongoDB, Express, Angular, Node)
  • MEVN (MongoDB, Express, Vue, Node)
  • Other
This is a subjective question and the correct answer will vary depending on the individual's experience and preferences. There is no one "correct" answer.

What is the use of refs?

  • To create references to DOM elements
  • To create references to component instances
  • To handle events
  • To manage state
Refs in React are used to create references to DOM elements. They allow developers to access and manipulate the properties and methods of DOM elements directly, without the need for additional logic or event handling. Refs are typically used when working with third-party libraries, or when manipulating the DOM directly is necessary.

How to pass numbers to React component?

  • Wrap the number in quotes as a string
  • Use the Number() constructor
  • Use the parseInt() or parseFloat() functions
  • Pass the number directly as a prop
To pass a number to a React component, you can simply pass the number directly as a prop. React will automatically handle the conversion of the number to a string when rendering the component. For example, you could pass a number like this: ' '. If you need to pass a number as a string, you can wrap it in quotes like any other string.

Why we need to be careful when spreading props on DOM elements?

  • It can cause security issues
  • It can cause the component to render incorrectly
  • It can spread invalid HTML attributes
  • It causes a performance issue
When spreading props on DOM elements, it is important to be careful because it can spread invalid HTML attributes. This can cause the component to render incorrectly or even create security vulnerabilities. It is recommended to only spread props on components that you trust, or to manually whitelist the valid attributes.