You are on the right track by including the official Google HTML client in your HTML header. That would not be ideal, it would be nice if Google provided an API (browser) as an npm module that you could import . But they donβt do it (I see), so I think you are doing well.
Then the question arises: "How can I use it so that React / Redux is friendly?" Redux is a mechanism for managing the state of your application. The Google API is not part of your application (although what you do with it may indicate the status of your application).
Itβs easy to verify that you have access to the Google API: you can just call from the componentDidMount method of one of your components and make a console log:
class MyComp extends React.Component { componentDidMount() { // this is taken directly from Google documentation: // https://developers.google.com/api-client-library/javascript/start/start-js function start() { // 2. Initialize the JavaScript client library. gapi.client.init({ 'apiKey': 'YOUR_API_KEY', // clientId and scope are optional if auth is not required. 'clientId': 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com', 'scope': 'profile', }).then(function() { // 3. Initialize and make the API request. return gapi.client.request({ 'path': 'https://people.googleapis.com/v1/people/me', }) }).then(function(response) { console.log(response.result); }, function(reason) { console.log('Error: ' + reason.result.error.message); }); }; // 1. Load the JavaScript client library. gapi.load('client', start); }, }
If you do not see what you expect from the console, somehow gapi does not load as you expect. If this happens, you will have a more specific question that you can ask!
If you get the answer, you now know how to invoke GAPI ... but then, how to use it in a Redux-friendly way?
When you make a GAPI call, you probably want to somehow change the state of your application (otherwise, why are you doing this?) For example, you can call an authentication flow, and when the GAPI returns success, your application state now has loggedIn: true or similar (possibly with a lot of other state changes). Where you make the GAPI call is up to you. If you want to do this when the component loads, you must do this in componentDidMount . You can also usually make a GAPI call in response to a user action, such as clicking a button.
So a typical thread would be something like this:
// either in componentDidMount, or a control handler, usually: someGapiCall() .then(result => { this.props.onGapiThing(result.whatever) })
Where this.props.onGapiThing is a function that dispatches an appropriate action that changes your application state.
I hope this review helps ... feel free to follow up on more specific issues.