ReactJS can't set state from an event with event.persist()

前端 未结 5 969
予麋鹿
予麋鹿 2020-12-08 00:15

I need to set a state field which I get from an event, but it doesn\'t get set when I pass a function to it. The component and method looks like the following:



        
5条回答
  •  萌比男神i
    2020-12-08 01:02

    I came across similar warning message when filling components dynamically and to solve this I just had to wrap function with arrow function.

    From:

    { text: "Delete item", onClick: deleteItem },
    

    To:

    { text: "Delete item", onClick: (id) => deleteItem(id) },
    

提交回复
热议问题