React Exercises
Fill in the blanks to test your knowledge.
1
Import the useState hook from React
import { } from "react";
2
Initialize a state variable called count
const [count, setCount] = (0);
3
Pass a name prop to a component
<Greeting ="Alice" />
4
Destructure props in a function component
function Card({ }) {
return <h1>{title}</h1>;
}
5
Import useEffect alongside useState
import { useState, } from "react";
6
Call useEffect with an empty dependency array
(() => {
fetchData();
}, );
7
Add a key prop when rendering a list
items.map(item => <li ={item.id}>{item.name}</li>)
8
Return JSX from a functional component
function App() {
<div>Hello</div>;
}