const { navigation, currentScreen, childIndex } = this.state
const screen = navigation[currentScreen]
如何在同一行中编写这两行代码?
使用{ [currentScreen]: screen }
,请确保您事先提取了currentScreen
:
const state = { navigation: { foo: 'val' }, currentScreen: 'foo' };
const { navigation, currentScreen, childIndex, navigation: { [currentScreen]: screen } } = state
console.log(screen);