0

I am working on a custom SPFx webpart. I wanted to know if there is a way to make the webpart close and/or re-open itself.

Ideally this would trigger when the user fills out the text fields in my webpart and hits the submit button, then the webpart would close and another instance of that webpart would open in its place.

Any advice on how to do this would be appreciated.

Thanks

Update: I'm adding a gif that explains what I'm trying to achieve. Whenever I click the submit button, I would like for the webpart to refresh itself. I am making a POST request in the render method, so having the webpart refresh would allow that request to be made again. Also, I would like the contents of the richtext field and the people picker to be cleared out when the user hits submit

ClearWebPart gif

2
  • Could you perhaps make it more clear what you want to achieve? Wouldn't it be enough for you to handle the onSubmit event and then re-render the web part if you wanted the user to be able to enter the form again? "Closing" the web part and creating another instance of it seems a bit off to me unless you have a really specific use-case for wanting to do it that way. Commented Feb 28 at 6:45
  • 1
    Agreed. You shouldn't be making a POST request from inside the render function. You should handle the button click event, make your POST request from there, and then (maybe if the request was successful?) clear the input controls. Are the inputs uncontrolled, or controlled through state? If you control them through state then clearing them is trivial. Commented Mar 7 at 22:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.