How to submit form from a button outside that component in React?

后端 未结 6 999
野趣味
野趣味 2020-12-31 02:07

I have a form in one of my React components, and and in the outside component that calls it I want to pass a reference to a button there, so that I can also submit that usin

6条回答
  •  庸人自扰
    2020-12-31 02:27

    None of these solutions worked for me, but I finally figured it out by doing

    document.forms[0].submit()
    

    Since there was only one form on the page, I selected it with the 0 index, but if there are multiple forms then you'd need to use the applicable index for the forms array.

提交回复
热议问题