Forum Discussion
Samaresh Das
Apr 04, 2017Copper Contributor
How to refresh SPFX webpart
I am developing webpart with new SharePoint Framework. I notice when user changed any value in property it refresh/reload the webpart. I want to refresh/reload the web part when user click on a button on the webpart. I did not find any solutionhow to do this. Please share ideas if anybody have.
13 Replies
Sort By
- Kushan Lahiru PereraCopper Contributor
component.forceUpdate(callback)
By default, when your component’s state or props change, your component will re-render. If your render() method depends on some other data, you can tell React that the component needs re-rendering by calling forceUpdate().
Calling forceUpdate() will cause render() to be called on the component, skipping shouldComponentUpdate(). This will trigger the normal lifecycle methods for child components, including the shouldComponentUpdate() method of each child. React will still only update the DOM if the markup changes.
Normally you should try to avoid all uses of forceUpdate() and only read from this.props and this.state in render().
- Mayank BakshiFormer Employee
Were you able to get the answer to your Original question ?
I want to refresh/reload the web part when user click on a button on the webpart
- paulpaschaBronze Contributor
I think wat you're looking for is described in this great blog by Waldek Mastykarz
https://blog.mastykarz.nl/sharepoint-framework-client-side-web-parts-non-reactive-property-pane/
- Samaresh DasCopper ContributorThanks for your reply but sorry to say you miss understand me. My objective, there will be a button in web part not in property pane. When user will click on the button from webpart it will refresh the webpart.
- paulpaschaBronze Contributor
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!