I am in the process of developing a stenciljs application and I am trying to fetch data from a REST service. The REST call is set up as a function that returns a Promise. When I use this rest call in the componentWillLoad Lifecycle Method, it functions as expected:
async componentWillLoad() {
return getUserData().then( userData => {
console.log("got userdata", userData);
});
}
Now, I want to retrieve this information when the user clicks a button. To achieve this, I invoke this method in the click handler for the button:
<button id="mybutton" onClick={()=>this._handleButtonClick()></button>
_handleButtonClick() {
return getUserData().then( userData => {
console.log("got userdata", userData);
});
}
However, this approach does not seem to work. Upon inspecting the Network Tab in the Browser console, I can see that a network request is being made but it does not return any data. How can I resolve this issue?