Can not read property 0 of undefined in reactjs

前端 未结 2 1619
抹茶落季
抹茶落季 2020-12-12 07:30

I have an application when user has the possibility to toggle between the components.The idea of the application is next:

  1. User click on add field butt
2条回答
  •  心在旅途
    2020-12-12 08:08

    Edit: I think setting state interferes with formVal updating.

    setTimeout(() => {
          setFieldsOnEdit(prevIndexes => [...prevIndexes, index]);
          setDefaultMode(false);
        }, 0);
    

    Placing it in a setTimeout resolves it.

提交回复
热议问题