2021年5月4日星期二

reactjs: pass variables as index while setting state variable [duplicate]

I have an onclick function

  function showNextSteps(row){      const next_row = row+1      setSteps(          function(prevState){            const obj = {              ...prevState,              row :{                ...prevState[row],                "ShowButton":false              },              next_row :{                ...prevState[row+1],                "ShowButton":true,                "ShowRow":true              }            }            return (obj)          }          )    }  

Here i want to use the index row as the value of row variable and same for next_row

enter image description here

But i see in my state there are new entries with row and row_value

enter image description here

How to pass the variable value to index in this case

I tried

`${row}` and `${net_row}` as indexes  

But i get unexpected token

enter image description here

https://stackoverflow.com/questions/67395046/reactjs-pass-variables-as-index-while-setting-state-variable May 05, 2021 at 12:03PM

没有评论:

发表评论