0
0
Reactframework~20 mins

What is a component in React - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
React Component Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does a React component represent?
In React, what does a component mainly represent?
AA reusable piece of UI that can have its own logic and appearance
BA function that directly manipulates the browser's DOM elements
CA database where React stores user data
DA CSS style sheet that controls the look of the app
Attempts:
2 left
💡 Hint
Think about how React builds parts of the screen.
component_behavior
intermediate
2:00remaining
What will this React component render?
Given this React component, what will it display on the screen?
React
function Greeting() {
  return <h1>Hello, friend!</h1>;
}
AA paragraph with the text 'Hello, friend!'
BA button labeled 'Hello, friend!'
CA heading with the text 'Hello, friend!'
DAn empty screen with no text
Attempts:
2 left
💡 Hint
Look at the HTML tag used inside the return statement.
state_output
advanced
2:00remaining
What is the output after clicking the button twice?
Consider this React component. What will be the displayed count after clicking the button two times?
React
import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increase</button>
    </div>
  );
}
ACount: undefined
BCount: 1
CCount: 0
DCount: 2
Attempts:
2 left
💡 Hint
Each click increases the count by 1.
📝 Syntax
advanced
2:00remaining
Which option correctly defines a React functional component?
Which of the following code snippets correctly defines a React functional component named 'Welcome' that returns a greeting?
Aconst Welcome = () => <h2>Welcome!</h2>;
Bfunction Welcome() { <h2>Welcome!</h2>; }
Cfunction Welcome() { <h2>Welcome!</h2> }
Dconst Welcome = () => { <h2>Welcome!</h2> }
Attempts:
2 left
💡 Hint
Remember that a component must return JSX to render.
lifecycle
expert
2:00remaining
What happens when the dependency array is empty in useEffect?
In React, what is the behavior of a useEffect hook with an empty dependency array like this? useEffect(() => { console.log('Effect ran'); }, []);
AThe effect runs only when the component unmounts.
BThe effect runs only once after the component mounts.
CThe effect never runs.
DThe effect runs after every render of the component.
Attempts:
2 left
💡 Hint
Think about when React runs effects with no dependencies.