I'm pretty new to react, and am working on a big existing codebase.
This website has a list of components (square blocks), and when I press on one of them (say Block1), I want that one (Block1) to change from white to a blue background color. If I press on another block (say Block3), then I want the previous block (Block1) to change back to white, and the block I just selected (Block3) to change to blue.
I have a List file with a functional component that returns a list of blocks, like so:
ItemList() {
return ({edge.map() => return <Block />}) //this basically returns like 10 Blocks
}
Block Component File
Block() {
return (<div> blah blah </div>)
}
What's the easiest way for me to do this? I currently have a state inside of the Block() component, but this isn't letting me update when I press on another block, and want this block to change back.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…