Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的东西
<Box> <SomethingA> </Box
我想替换Box.SomethingA为Box.SomethingB
Box.SomethingA
Box.SomethingB
<Box> <SomethingB> </Box>
我猜你想在事件发生后替换它,例如:button click. 你可以试试这个:
button click
function App(){ const [box, changeBox] = useState(true) return( <div> <button onClick={()=>{changeBox(!box)}} >Click</button> <Box> { box ? <SomethingA/> : <SomethingB/>} </Box> </div> ) }