How to conditionally apply class attributes?

  • Using the "class" attribute and a ternary operator
  • Using the "class" attribute and an if statement
  • Using the "className" attribute and a ternary operator
  • Using the "className" attribute and an if statement
In React, you can conditionally apply class attributes by using the "className" attribute and a ternary operator. This allows you to add or remove classes based on some condition, such as the state of the component. The "className" attribute is used instead of the "class" attribute in React, because "class" is a reserved keyword in JavaScript.

How Redux Form initialValues get updated from state?

  • initialValues are automatically synced with the Redux store
  • You need to manually update initialValues in the form component
  • initialValues are passed in as a prop to the form component
The initialValues prop in Redux Form is used to set the initial values for the form fields. You can pass in an object of initial values as the initialValues prop, which will be used to populate the form fields when the form is first rendered. The initialValues can be sourced from the Redux store, and can be updated by dispatching an action that updates the relevant values in the store. The form component will automatically update when the initialValues prop changes.

What is a switching component?

  • A component that animates between different states
  • A component that changes its state based on user input
  • A component that provides an interface for switching between different pages
  • A component that switches between multiple child components
A switching component in React is a component that renders one of several child components based on some condition or state. This is commonly used to switch between different views or user interface elements in response to user input or other events.

What is the purpose of ReactTestUtils package?

  • To generate test data
  • To mock HTTP requests
  • To simulate component rendering without deep rendering
  • To test React components
The ReactTestUtils package provides a set of utilities for testing React components. It allows developers to simulate events, perform component rendering, and find components in the rendered output. It is commonly used in combination with Jest or another testing framework.

Does React support all HTML attributes?

  • Yes, React supports all HTML attributes
  • No, React only supports a subset of HTML attributes
React supports a subset of HTML attributes, as not all attributes are applicable or relevant to React components. Some HTML attributes, such as "class" and "for", are reserved words in JavaScript and cannot be used directly in JSX. Instead, React uses the "className" and "htmlFor" attributes, respectively. Additionally, some HTML attributes may have different names or syntax in React, such as "tabindex" being spelled "tabIndex" in React.

What is the purpose of the constants in Redux?

  • To make the code easier to read and understand
  • To prevent changes to the action types
  • To enable minification and other performance optimizations
Constants in Redux are used to define action types, which are used to identify the type of action being dispatched to the Redux store. By using constants, you can prevent unintended changes to the action types and make it easier to understand the purpose of each action.

How to import and export components using react and ES6?

  • Use the "export" keyword to export components
  • Use the "import" keyword to import components
  • Use the "module.exports" object to export components
  • Use the "require" keyword to import components
In React and ES6, you can import and export components using the "import" and "export" keywords. To import a component, you can use the "import" keyword followed by the component name and file path. To export a component, you can use the "export" keyword before the component declaration. For example: import React from 'react'; export class MyComponent extends React.Component { ... }.

Why is isMounted() an anti-pattern and what is the proper solution?

  • It can lead to race conditions and bugs
  • It causes performance issues
  • It is not needed in modern versions of React
  • It is not supported in React v16
The "isMounted" method in React is considered an anti-pattern because it can lead to race conditions and bugs. This method checks if the component is mounted to the DOM, but it can return a false positive if it is called during the unmounting phase. The proper solution is to use the "componentDidMount" and "componentWillUnmount" lifecycle methods to manage component state and cleanup.

Why should component names start with capital letter?

  • It ensures proper scoping of the component
  • It improves the performance of the component
  • It is a convention that makes the code easier to read
  • It is a requirement of the React compiler
In React, component names should start with a capital letter in order to distinguish them from regular HTML tags and make the code easier to read. This is a convention that is widely used in the React community and helps developers understand the purpose and scope of different parts of the code.

Can I use javascript urls in react16.9?

  • Yes
  • No
JavaScript URLs are not allowed in React16.9 or any modern web development framework due to security concerns. JavaScript URLs are URLs that begin with "javascript:", and they allow for the execution of arbitrary JavaScript code when clicked. This can be used for malicious purposes, such as stealing user data or injecting malware. Instead of using JavaScript URLs, developers should use event handlers and other safe mechanisms to handle user interactions.