Programming Exercises

Write a React component that displays the name of a selected option from a hardcoded dropdown menu.

Easy

Problem Statement

Write a React component that displays the name of a selected option from a hardcoded dropdown menu.

Sample Input

Options: ['React', 'Angular', 'Vue']

Sample Output

Initially: Selected: React
 After selection: Selected: [chosen option]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React, { useState } from "react"; const Dropdown = () => { const [selected, setSelected] = useState("React"); return ( <div> <select onChange={(e) => { // Update the selected value }}> <option>React</option> <option>Angular</option> <option>Vue</option> </select> <p>Selected: {selected}</p> </div> ); }; export default Dropdown;
Log in or sign up to run or submit your code.Log inSign up
Input
Options: ['React', 'Angular', 'Vue']
Expected Output
Initially: Selected: React
 After selection: Selected: [chosen option]