Forum Discussion
How to refresh SPFX webpart
I'm sorry I misunderstood...
Regarding your question then I think it all comes down to attaching an event handler to the button's click event, perform whatever logic needed to refresh and ultimately making sure your HTML is updated.
Maybe the information in the following article helps you out
https://www.w3schools.com/jsref/event_onclick.asp
Hope this helps!
- Samaresh DasApr 04, 2017Copper ContributorI am able to fire the click event and execute my custom code. Here need to fire a sharepoint framework method to refresh the webpart, so i need the sample code of SPFX webpart refresh method.
- paulpaschaApr 05, 2017Bronze Contributor
So what you want to achieve is to update a property through the rendered Web Part instead of through its Property Pane and refresh the Web Part after update to reflect the property change?
- Samaresh DasApr 05, 2017Copper Contributor
Hi Paul,
In my post i raised the property as example it is not my target. My target is refresh the webpart progmatically when user click on the button. The button will be render in initial loading.
- Luis MaƱezApr 05, 2017MVP
I don't think there's a specific method to refresh the webpart itself. Are you using ReactJS in the webpart? in that case, if you follow ReactJS component lifecycle, the component re-renders when the state is updated. If you are using just JavaScript, and you say you're able to catch the event, then you need to refresh the DOM setting the new values.
- Samaresh DasApr 05, 2017Copper ContributorHi Luis,
I am not using any javascript framwork. I am able to manage the change DOM. But it would nice if framwork expose any interface to refresh the webpart programatically.