.sign not worked
ItaloCobains opened this issue · comments
Italo Brandão commented
I have the following code.
'use client'
import { SyntheticEvent } from 'react'
import ApiCalendar from 'react-google-calendar-api'
export const useGoogleCalendar = () => {
const calendar = new ApiCalendar({
clientId: process.env.NEXT_PUBLIC_CLIENT_ID as string,
apiKey: process.env.NEXT_PUBLIC_API_KEY as string,
scope: "https://www.googleapis.com/auth/calendar",
discoveryDocs: [
"https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest",
],
})
const handleItemClick = (event: SyntheticEvent<any>, name: string) => {
console.info('Funcao handleItemClick', event, name)
if (name === 'sign-in') {
calendar.handleAuthClick();
} else if (name === 'sign-out') {
calendar.handleSignoutClick();
}
};
return {
api: calendar,
handleItemClick,
}
}
When I click on the button that launches one of these events, the api.sign
variable never changes value. Is this correct?
Kubessandra commented
From what I see, useGoogleCalendar seems to be hook.
You probably need to have the calendar variable in a state or a ref, otherwise it will be re-created each time you go in the function.
You can verify that by adding a console.log just before the new ApiCalendar and see how many times is this called.