在 React 中,我经常使用这种语法进行条件渲染:
const exampleState = 1;
const retval = {
0: "Value for state 0",
1: "Value for state 1",
2: "Value for state 2",
}[exampleState]
// this returns "Value for state 1"
这种语法叫什么?
编辑:添加const retval
以使其成为实际有效的代码