I have this function in an external file js:
export function getCalendarEvents() {
gapi.client.load('calendar', 'v3', ()=> { // load the calendar api (version 3)
var request = gapi.client.calendar.events.list({
'calendarId': 'primary', // calendar ID
'maxResults': 20, // show max of 20 events
'singleEvents': true, // split recurring events into individual events
'timeMin': (new Date()).toISOString(),
'orderBy': 'startTime' // order events by their start time
});
// handle the response from our api call
request.execute((resp) => {
for (var i = 0; i < resp.items.length; i++) { // loop through events and write them out to a list
console.log(resp.items[i].summary + ' ' +resp.items[i].start.dateTime);
};
});
});
}
and i need to use "resp.items" value in my enter js file:
import {getCalendarEvents} from './GoogleCalendarEvents';
componentWillMount(){
var myitems = getCalendarEvents(); //my resp.items
}
How can i do that? I know there are a lot of response but i want to understand the asynchronous pattern on my example.