You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you don't have an OAuth token, you can listen for the `"picker:authenticated"` event to get the token after the user has authenticated. This library wraps the [Google Identity Servies library](https://developers.google.com/identity/oauth2/web/guides/overview) to make it easier to authenticate users.
98
+
If you don't have an OAuth token, you can listen for the `"picker-oauth-response"` event to get the token after the user has authenticated. This library wraps the [Google Identity Services library](https://developers.google.com/identity/oauth2/web/guides/overview) to make it easier to authenticate users.
99
99
100
100
### Listening to Events
101
101
@@ -108,19 +108,20 @@ The `drive-picker` component emits several events that you can listen to. Here i
Most of these events return the [`Picker ResponseObject`](https://developers.google.com/drive/picker/reference/picker.responseobject) as the event detail. For example, the `"picker:picked"``CustomEvent` contains details about the selected files:
120
+
Most of these events return the [`Picker ResponseObject`](https://developers.google.com/drive/picker/reference/picker.responseobject) as the event detail. For example, the `"picker-picked"``CustomEvent` contains details about the selected files:
120
121
121
122
```js
122
123
{
123
-
"type":"picker:picked",
124
+
"type":"picker-picked",
124
125
"detail": {
125
126
"action":"picked",
126
127
"docs": [
@@ -137,13 +138,16 @@ Most of these events return the [`Picker ResponseObject`](https://developers.goo
137
138
}
138
139
```
139
140
140
-
The `"picker:authenticated"` event returns the `token` as the event detail:
141
+
The `"picker-oauth-response"` event returns the OAuth token response as the event detail:
The above snippet can be added to a declaration file (e.g. `app.d.ts`) in your React project.
196
200
201
+
#### Using Events in React/Next.js
202
+
203
+
When working with React or Next.js, you need to use `useEffect` and `useRef` to properly attach event listeners to the web component. Here's a complete example:
1.**Dynamic import**: In Next.js, import the component dynamically inside `useEffect` to avoid server-side rendering issues, since web components need to run in the browser.
281
+
282
+
2.**Proper cleanup**: Always remove event listeners in the cleanup function to prevent memory leaks.
283
+
284
+
3.**Wait for the element**: Make sure the ref is populated before adding event listeners.
285
+
197
286
## Support
198
287
199
288
To report issues or feature requests for the underlying Drive Picker, please use the [Google Picker issue tracker](https://developers.google.com/drive/picker/support#developer_product_feedback). For all other issues, please use the [GitHub issue tracker](https://github.com/googleworkspace/drive-picker-element/issues).
0 commit comments