📅  最后修改于: 2022-03-11 15:02:53.592000             🧑  作者: Mango
import React, { useState } from "react";
export default function App() {
const Colors = ["red", "green"];
return (
Hello CodeSandbox
Start editing to see some magic happen!
{Colors.map((color, key) => (
))}
);
}
function Button({ Color, Colors }) {
const [color, setColor] = useState(Color);
const handleChange = (e) => {
e.preventDefault();
setColor(Colors[Math.floor(Math.random() * Colors.length)]);
};
const style = {
backgroundColor: color
};
return (
);
}