新的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...
}
是我的思想的声音?这是做事的“反应”方式吗?