Forum Discussion

Samaresh Das's avatar
Samaresh Das
Copper Contributor
Apr 04, 2017

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

  • 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().

     

     

    Samaresh Das 

  • 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

    • Samaresh Das's avatar
      Samaresh Das
      Copper Contributor
      Thanks 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.
      • paulpascha's avatar
        paulpascha
        Bronze 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!

         

Resources