React JS MCQs 9
React JS MCQs 9
Topics : React JS
Written on May 10, 2024
O
81. Which of the following statements correctly imports React in a JSX file?
N
b) require('react');
c) import { React } from 'react';
d) import React from 'React';
H
82. What is the purpose of the following code snippet in a React component?
C
import React from 'react';
TE
function MyComponent() {
return (
<div>Hello, world!</div>
);
}
YA
83. In React, what is the correct syntax for rendering a JavaScript expression inside JSX?
a) { var }
b) {{ var }}
c) { var } (Correct Answer)
d) {{ var }}
function MyComponent() {
const items = ['apple', 'banana', 'orange'];
return (
<ul>
{items.map(item => <li key={item}>{item}</li>)}
</ul>
);
}
85. In React, which lifecycle method is called immediately after a component is mounted?
a) componentWillMount()
b) componentDidMount() (Correct Answer)
O
c) componentWillUnmount()
d) componentDidUpdate()
N
86. What is the correct way to pass props to a component in React?
H
b) <MyComponent {props} />
c) <MyComponent {...props} /> (Correct Answer)
d) <MyComponent props={{data}} />
C
87. What is the purpose of the following React code snippet?
TE
function MyComponent() {
const [count, setCount] = useState(0);
YA
return (
<div>
<p>You clicked {count} times</p>
AR
a) It defines a functional component with a state variable named count that increments
on button click (Correct Answer)
b) It renders a paragraph element with the text "You clicked {count} times"
c) It renders a button element with the text "Click me"
d) It imports the useState hook from the React library
88. In React, what is the purpose of the key attribute when rendering a list of components?
90. In React, what is the purpose of the onClick attribute in a button element?
O
a) It defines the button's appearance
b) It specifies the action to be performed when the button is clicked (Correct Answer)
c) It triggers the button's hover effect
N
d) It determines the button's accessibility properties
H
© Copyright Aryatechno. All Rights Reserved. Written tutorials and materials by Aryatechno
C
TE
YA
AR