I am trying to use google api with a next.js app. I was reading the documentation and the next.js recommendation for implementing google api is to use next.js Head component. I loaded the script but can't seem to access the gapi property...
export default () => (
<div>
<Head>
<link href="/static/styles.css" rel="stylesheet" />
<script
src="https://apis.google.com/js/platform.js?onload=init"
async
defer
></script>
</Head>
<Login />
</div>
);
My GoogleClient file starts with
const GoogleClient = ({api}) => {
...
}
I used a Login component that initializes the GoogleClient file as
const Login = () => {
useEffect(()=> {
GoogleClient(window.gapi)
}, [])
...
}
When I console.log window the gapi property exists on the window object but when I call window.gapi I get the following error --> Property 'gapi' does not exist on type 'Window & typeof globalThis'. I googled the error but haven't seen any posts on how to fix it.