[英]How to replace a React Components with another React Components?
我有這樣的東西
<Box>
<SomethingA>
</Box
我想將Box.SomethingA
替換為Box.SomethingB
<Box>
<SomethingB>
</Box>
我猜你想在事件發生后替換它,例如: button click
。 你可以試試這個:
function App(){
const [box, changeBox] = useState(true)
return(
<div>
<button onClick={()=>{changeBox(!box)}} >Click</button>
<Box>
{ box ? <SomethingA/> : <SomethingB/>}
</Box>
</div>
)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.