Skip to content

Commit b8c5bd4

Browse files
committedJan 20, 2024
feat: add color-dropdown.jsx solution
1 parent a6d33d5 commit b8c5bd4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎solutions/color-dropdown.jsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { useState } from "react"
2+
import { createRoot } from "react-dom/client"
3+
4+
function ColorSelector() {
5+
const colors = { red: "Red", blue: "Blue", green: "Green" }
6+
const [color, setColor] = useState(colors.red)
7+
const onChange = e => setColor(e.target.value)
8+
return (
9+
<>
10+
<select onChange={onChange} value={color}>
11+
<option value={colors.red}>{colors.red}</option>
12+
<option value={colors.blue}>{colors.blue}</option>
13+
<option value={colors.green}>{colors.green}</option>
14+
</select>
15+
{color && <p>{`You have selected: ${color}`}</p>}
16+
</>
17+
)
18+
}
19+
20+
const root = createRoot(document.getElementById("root"))
21+
root.render(<ColorSelector />)

0 commit comments

Comments
 (0)
Please sign in to comment.