React.js MCQ: React.js Multiple Choice Questions and Answers

React.js MCQ with answers and explanations for placement tests and job interviews. These solved React.js MCQ are useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our React.js MCQ (React.js multiple Choice Questions ) focuses on all areas of React.js and its concept. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

If you want to learn React.js in detail you can follow these courses created by industry experts, Trial of some courses is free.

Guideline of React.js MCQ:

This React.js MCQ is intended for checking your React.js knowledge. It takes 1 hour to pass the React.js MCQ. If you don’t finish the React.js MCQ within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on React.js has features of randomization which feel you a new question set at every attempt.

In this React.js MCQ, we have also implemented a feature that not allowed the user to see the next question or finish the quiz without attempting the current React.js MCQ.

10 votes, 4.1 avg

You have 1 hours to take the React.JS MCQs

Your time has been Over.


React.js MCQ

React JS MCQ

React.js MCQ: React.js Multiple Choice Questions and Answers

1 / 61

Consider the following component. What is the default color for the star?

const Star = ({ selected = false }) => <Icon color={selected ? 'red' : 'grey'} />;

 

2 / 61

What is the name of this component?

class Clock extends React.Component {
  render() {
    return <h1>Look at the time: {time}</h1>;
  }
}

 

3 / 61

How do you invoke setDone only when component mounts, using hooks?

function MyComponent(props) {
  const [done, setDone] = useState(false);

  return <h1>Done: {done}</h1>;
}

 

4 / 61

Why is it a good idea to pass a function to setState instead of an object?

5 / 61

You have created a new method in a class component called handleClick, but it is not working. Which code is missing?

class Button extends React.Component{

  constructor(props) {
    super(props);
    // Missing line
  }

  handleClick() {...}
}

 

6 / 61

Currently, handleClick is being called instead of passed as a reference. How do you fix this?

<button onClick={this.handleClick()}>Click this</button>

 

7 / 61

How do you destructure the properties that are sent to the Dish component?

function Dish(props) {
  return (
    <h1>
      {props.name} {props.cookingTime}
    </h1>
  );
}

 

8 / 61

When do you use useLayoutEffect?

9 / 61

What does this React element look like given the following function? (Alternative: Given the following code, what does this React element look like?)

React.createElement('h1', null, "What's happening?");

 

10 / 61

What package contains the render() function that renders a React element tree to the DOM?

11 / 61

If a function component should always render the same way given the same props, what is a simple performance optimization available for it?

12 / 61

Which function is used to update state variables in a React class component?

13 / 61

Per the following code, when is the Hello component displayed?

const greeting = isLoggedIn ? <Hello /> : null;

 

14 / 61

How do you set a default value for an uncontrolled form field?

15 / 61

Consider the following code from React Router. What do you call :id in the path prop?

<Route path="/:id" />

 

16 / 61

How do you handle passing through the component tree without having to pass props down manually at every level?

17 / 61

What is the testing library most often associated with React?

18 / 61

All React components must act like **\_\_** with respect to their props.

19 / 61

Which attribute do you use to replace innerHTML in the browser DOM?

20 / 61

React components are composed to create a user interface. How are components composed?

21 / 61

What is the children prop?

22 / 61

Why might you use a ref?

23 / 61

What do you call the message wrapped in curly braces below?

const message = 'Hi there';
const element = <p>{message}</p>;

 

24 / 61

If you see the following import in a file, what is being used for state management in the component?

import React, {useState} from 'react';

 

25 / 61

What is sent to an Array.map() function?

26 / 61

What do you need to change about this code to get it to run?

class clock extends React.Component {
  render() {
    return <h1>Look at the time: {this.props.time}</h1>;
  }
}

 

27 / 61

Which library does the fetch() function come from?

28 / 61

What is the children prop?

29 / 61

Which props from the props object is available to the component with the following syntax?

<Message {...props} />

 

30 / 61

Which Hook could be used to update the document's title?

31 / 61

In the following code block, what type is orderNumber?

ReactDOM.render(<Message orderNumber="16" />, document.getElementById('root'));

 

32 / 61

If you wanted to display the count state value in the component, what do you need to add to the curly braces in the h1?

class Ticker extends React.component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  render() {
    return <h1>{}</h1>;
  }
}

 

33 / 61

What will happen when this useEffect Hook is executed, assuming name is not already equal to John?

useEffect(() => {
  setName('John');
}, [name]);

 

34 / 61

What should the console read when the following code is run?

const [, , animal] = ['Horse', 'Mouse', 'Cat'];
console.log(animal);

 

35 / 61

If you created a component called Dish and rendered it to the DOM, what type of element would be rendered?

function Dish() {
  return <h1>Mac and Cheese</h1>;
}

ReactDOM.render(<Dish />, document.getElementById('root'));

 

36 / 61

Why might you use useReducer over useState in a React component?

37 / 61

Which answer best describes a function component?

38 / 61

To get the first item from the array ("cooking") using array destructuring, how do you adjust this line?

const topics = ['cooking', 'art', 'history'];

 

39 / 61

Using object literal enhancement, you can put values back into an object. When you log person to the console, what is the output?

const name = 'Rachel';
const age = 31;
const person = { name, age };
console.log(person);

 

40 / 61

When using webpack, why would you need to use a loader?

41 / 61

To create a constant in JavaScript, which keyword do you use?

42 / 61

In which lifecycle method do you make requests for data in a class component?

43 / 61

What can you use to wrap Component imports in order to load them lazily?

44 / 61

What value of button will allow you to pass the name of the person to be hugged?

class Huggable extends React.Component {
  hug(id) {
    console.log("hugging " + id);
  }

  render() {
    let name = "kitteh";
    let button = // Missing Code
    return button;
  }
}

 

45 / 61

You have written the following code but nothing is rendering. How do you fix this problem?

const Heading = () => {
  <h1>Hello!</h1>;
};

 

46 / 61

What is the children prop?

47 / 61

How do you fix the syntax error that results from running this code?

const person =(firstName, lastName) =>
{
  first: firstName,
  last: lastName
}
console.log(person("Jill", "Wilson"))

 

48 / 61

When might you use React.PureComponent?

49 / 61

A representation of a user interface that is kept in memory and is synced with the "real" DOM is called what?

50 / 61

If you created a component called Dish and rendered it to the DOM, what type of element would be rendered?

function Dish() {
  return <h1>Mac and Cheese</h1>;
}

ReactDOM.render(<Dish />, document.getElementById('root'));

 

51 / 61

What is the name of the tool used to take JSX and turn it into createElement calls?

52 / 61

You have added a style property to the h1 but there is an unexpected token error when it runs. How do you fix this?

const element = <h1 style={ backgroundColor: "blue" }>Hi</h1>;

 

53 / 61

If you want to import just the Component from the React library, what syntax do you use?

54 / 61

. What do you call a React component that catches JavaScript errors anywhere in the child component tree?

55 / 61

What can you use to handle code splitting?

56 / 61

What property do you need to add to the Suspense component in order to display a spinner or loading state?

function MyComponent() {
  return (
    <Suspense>
      <div>
        <Message />
      </div>
    </Suspense>
  );
}

 

57 / 61

Which choice will not cause a React component to rerender?

58 / 61

Why is it important to avoid copying the values of props into a component's state where possible?

59 / 61

What is the difference between the click behaviors of these two buttons (assuming that this.handleClick is bound correctly)?

A. <button onClick={this.handleClick}>Click Me</button>
B. <button onClick={event => this.handleClick(event)}>Click Me</button>

 

60 / 61

What is [e.target.id] called in the following code snippet?

handleChange(e) {
  this.setState({ [e.target.id]: e.target.value })
}

 

61 / 61

Which of these terms commonly describe React applications?

Your score is

The average score is 0%

0%

Recommended Articles for you: