考虑我有一个这样的 App 组件:
import React from "react";
import Component from "./component";
function App() {
const array = [
{ key : 1 } , { key : 2 } , { key : 3 } , { key : 4 }
]
return (
<div>
{array.map( (item) => {
<Component key={item.key} />
})}
</div>
);
}
export default App;
组件是:
import React , { useState } from "react";
function Component() {
const [ style , setStyle ]= useState({
height:"50px",width:"50px",backgroundColor:"blue"
});
return (
<div style={style} onclick={} >
Content
</div>
);
}
export default Component;
这将创建一个 App div,其中将有四个子 div 元素。
我想要的是; 每当我单击其中一个内部 div 时,其余三个 div 必须将其颜色更改为红色。不是一次,而是每次我单击四个中的任何一个时。
一只斗牛犬
FFIVE
ITMISS
相关分类