What are render props?

  • A technique for passing functions as props to child components
  • A technique for passing state as props to child components
  • A technique for rendering components as props to child components
  • A technique for rendering state as props to child components
Render props is a technique in React where a component exposes a function prop that returns another component or element. This allows the child component to use the parent's logic or state, and can be used to create reusable, composable components. For example: } />.

How do you update rendered elements?

  • By calling setState()
  • By calling forceUpdate()
  • By manipulating the DOM directly
  • By re-rendering the entire application
In React, rendered elements are updated by calling the setState() method. When setState() is called, React re-renders the component and updates the UI accordingly. Manipulating the DOM directly is not recommended in React, as it can cause bugs and performance issues.

When to use a Class Component over a Function Component?

  • When handling complex state and lifecycle methods
  • When rendering simple UI components
  • When using Redux
  • When using TypeScript
Class components in React are used when handling complex state and lifecycle methods. They provide additional functionality over function components, such as the ability to use lifecycle methods like componentDidMount and componentDidUpdate, and to maintain internal state. Function components are generally used for rendering simple UI components, while class components are used for more complex functionality.

What is React?

  • A JavaScript library for building user interfaces
  • A database management system
  • A markup language
  • A programming language
React is a JavaScript library for building user interfaces. It was developed by Facebook and is now maintained by a community of developers. React allows developers to create reusable UI components using JavaScript. These components can then be combined to create complex user interfaces.

What is the difference between mapStateToProps() and mapDispatchToProps()?

  • mapStateToProps() maps state to props, while mapDispatchToProps() maps props to state
  • mapStateToProps() is used for dispatching actions, while mapDispatchToProps() is used for mapping state to props
  • mapStateToProps() maps state to props, while mapDispatchToProps() maps dispatch functions to props
  • There is no difference
mapStateToProps() is used to map the application state to the props of a React component, while mapDispatchToProps() is used to map dispatch functions to the props of a React component. The dispatch functions are used to dispatch actions to the Redux store, allowing the component to update the application state.

How to define constants in React?

  • Use the "const" keyword to define constants
  • Use the "define" method to define constants
  • Use the "let" keyword to define constants
  • Use the "var" keyword to define constants
In React, you can define constants using the "const" keyword. Constants are variables that cannot be reassigned or redeclared, and are used to store values that will not change throughout the lifetime of the component. For example: const API_KEY = '12345';.

How to pretty print JSON with React?

  • Use the JSON.format() method
  • Use the JSON.parse() method
  • Use the JSON.prettify() method
  • Use the JSON.stringify() method
In React, you can pretty print JSON data by using the "JSON.stringify()" method with a "null" value for the "replacer" parameter and a number value for the "space" parameter. This will format the JSON data with indentation and line breaks for readability. For example: JSON.stringify(myData, null, 2).

What are uncontrolled components?

  • Components that are managed by React and cannot be updated directly
  • Components that are updated using refs
  • Components that are updated using the setState() method
  • Components that store their own state
Uncontrolled components are components that store their own state and are updated using refs. They are often used for simple form inputs, where managing the state in a parent component would be unnecessary overhead.

How to implement default or NotFound page?

  • Use the component
  • Use the syntax
  • Use the syntax
  • Use the syntax
In React Router v4, you can implement a default or NotFound page by using a component to render the first matching child , and adding a as the last child. This route will match any path that has not been matched by other routes, and render the NotFound component.

What is Shallow Renderer in React testing?

  • A testing framework for React
  • A tool for simulating component rendering without deep rendering
  • A package for generating test data
  • A package for mocking HTTP requests
Shallow Renderer is a tool for simulating component rendering without deep rendering. It can be used for testing components in isolation and allows developers to easily check the output of a component's render method.