Introduction to React

Last Updated :
Discuss
Comments

Question 1

What does the following line do in a React file?

JavaScript
import React from 'react';


  • A

    Runs the React application

  • B

    Imports the React library to use JSX and components

  • C

    Imports only hooks like useState and useEffect

  • D

    Initializes the DOM for rendering

Question 2

React follows which type of architecture for building UIs?

  • A

    Template-driven architecture

  • B

    MVC (Model-View-Controller) architecture

  • C

    Component-based architecture

  • D

    Layered architecture

Question 3

Which is the correct way to pass a prop named username with value "Anil" to the Greet component?

  • <Greet username="Anil" />

  • <Greet {username="Anil"} />

  • <Greet props.username="Anil" />

  • <Greet name=username />

Question 4

Identify the output of this component:

JavaScript
function Greeting() {
  return <h1>Hello, welcome to React!</h1>;
}


  • A

    Displays nothing

  • B

    Displays "Hello, World!"

  • C

    Displays "Hello, welcome to React!"

  • D

    Causes a compilation error

Question 5

If multiple components need the same state data, what is the recommended approach?

  • A

    Duplicate the state in each component

  • B

    Pass state as props from their nearest common ancestor

  • C

    Use CSS variables to share data

  • D

    Avoid using state entirely

Question 6

What is the default development server port when running a Vite React app?


  • A

    3000

  • B

    5000

  • C

    5173

  • D

    8080

Question 7

When using Vite to set up a React project, which command is correct?


  • A

    vite create react-app my-app

  • B

    npm create vite@latest my-app --template react

  • C

    npx create-react-app my-app

  • D

    npm install react-vite

Question 8

In React, what is the main difference between props and state?

  • A

    Props are mutable, state is immutable

  • B

    Props are passed from parent, state is managed within the component

  • C

    Both are the same, just used differently

  • D

    State can be shared across components, props cannot

Question 9

What is the purpose of the ReactDOM.render method?

  • A

    To manage application state

  • B

    To compile JSX into JavaScript

  • C

    To render a React component into the DOM

  • D

    To define the Virtual DOM

Question 10

What will be the output of this React code?

JavaScript
import React from 'react';
import ReactDOM from 'react-dom';
function App() {
    const greeting = "Hello";
    return <h1>{greeting} World</h1>;
}
ReactDOM.render(<App />, document.getElementById('root'));
  • A

    Hello World

  • B

    {greeting} World

  • C

    "Hello World"

  • D

    Error

There are 10 questions to complete.

Take a part in the ongoing discussion