新的reactJS和我試圖讓我的組件之一交替通過許多CRUD狀態(創建對象,列出對象,更新對象,刪除對象),每個組件將顯示適當的形式。 ..reactJS如何在很多應用程序狀態之間切換
我想這樣做,但我不明白我的想法是否有缺陷。
constructor() {
super(props);
this.state = {
list: true,
edit: false,
create: false,
// and so on for CRUD operations
}
再後來會有一個方法......
handleCRUDViewChange(newView) {
// flip everything to false...
// turn the correct one to true
}
然後在渲染會是這樣的......
switch (true) {
case this.state.list:
<ListComponent />
case this.state.edit:
<EditComponent />
// and so on...
}
是我的思想的聲音?這是做事的「反應」方式嗎?