📌  相关文章
📜  反应中的按钮颜色更改循环 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:53.592000             🧑  作者: Mango

代码示例1
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 ( ); }