Cannot read property 'someProperty' of undefined in react

后端 未结 2 1979
误落风尘
误落风尘 2021-01-23 20:55

I am working on an application where I pass variable values in a Navlink using state from one component to the other and then load those received values in input fields and clic

2条回答
  •  春和景丽
    2021-01-23 21:39

    I would suggest to just use arrow functions for setId and addOrEdit.

    addOrEdit = (e) => {
        // ...
    }
    

    And just call them:

    onChange={this.setId}
    onClick={this.addOrEdit}
    

    https://medium.com/@machnicki/handle-events-in-react-with-arrow-functions-ede88184bbb

    Also you are deriving state from prop. It is better to just use the prop directly.

    https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html

提交回复
热议问题