Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the main React library.
React
import [1] from 'react';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reactDOM instead of React
Importing useState directly here
✗ Incorrect
The main React library is imported using React.
2fill in blank
mediumComplete the code to create a functional component named App.
React
function [1]() { return <div>Hello World</div>; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Main' or 'Root' instead of 'App'
✗ Incorrect
The main component is usually named App in React projects.
3fill in blank
hardFix the error in the import statement for a component named Header.
React
import [1] from './components/Header';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for components
Misspelling the component name
✗ Incorrect
Component names in React must start with a capital letter, so Header is correct.
4fill in blank
hardFill both blanks to export the App component as default and import React.
React
[1] React from 'react'; function App() { return <div>Welcome</div>; } export [2] App;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'export' instead of 'import' for React
Not using 'default' in export
✗ Incorrect
We import React with import and export the component as default.
5fill in blank
hardFill all three blanks to create a React component that uses useState to toggle text.
React
import React, [1] from 'react'; function Toggle() { const [isOn, setIsOn] = [2](false); return ( <button onClick={() => setIsOn(!isOn)}> { [3] ? 'ON' : 'OFF' } </button> ); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using useEffect or useRef instead of useState
Using wrong variable name in JSX
✗ Incorrect
We import useState, call it to create state, and use the state variable isOn to show text.