npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@geniux/google-drive-picker-react

v1.0.0

Published

A React integration for Google Drive Picker, leveraging @geniux/google-drive-picker-core for Google Identity Services and Google Drive Picker functionality.

Downloads

149

Readme

@geniux/google-drive-picker-react

A React integration for Google Drive Picker, leveraging @geniux/google-drive-picker-core for Google Identity Services and Google Drive Picker functionality.

This package provides an easy-to-use setup for React applications to enable file selection from Google Drive.


Features

  • Easy OAuth Initialization: Leverages Google Identity Services for secure OAuth token handling.
  • Google Drive Picker with React Hooks: Simplifies integration with hooks and context providers.
  • Typed Interfaces: Includes TypeScript types for Google Picker and OAuth, including Google Drive API scopes.
  • Multi-Select Support: Allows selection of multiple files from Google Drive.

Installation

To install @geniux/google-drive-picker-react, use your preferred package manager:

pnpm add @geniux/google-drive-picker-react

or

npm install @geniux/google-drive-picker-react

or

yarn add @geniux/google-drive-picker-react

Basic Usage

Wrap Your App with the Provider

Wrap your app with the GoogleDrivePickerProvider, passing in your clientId and apiKey.

import { GoogleDrivePickerProvider } from '@geniux/google-drive-picker-react';

const App = () => (
  <GoogleDrivePickerProvider clientId="YOUR_GOOGLE_CLIENT_ID" apiKey="YOUR_GOOGLE_API_KEY">
    <YourComponent />
  </GoogleDrivePickerProvider>
);

Using the Picker in Your Component

Use the useGoogleDrivePicker hook to open the Google Drive Picker and manage selected files.

import { useGoogleDrivePicker } from '@geniux/google-drive-picker-react';

const YourComponent = () => {
  const { openPicker, selectedFiles } = useGoogleDrivePicker({
    allowMultiSelect: true,
    scopes: ['https://www.googleapis.com/auth/drive.file'], // This scope is already default for the picker, but you can define others.
  });

  return (
    <div>
      <button onClick={openPicker}>Open Google Drive Picker</button>
      <ul>
        {selectedFiles.map((file) => (
          <li key={file.id}>{file.name}</li>
        ))}
      </ul>
    </div>
  );
};

Next.js Compatibility

For Next.js users, you may encounter SSR (Server-Side Rendering) issues due to the way Next.js handles client-side scripts in packages that use barrel files (index files that re-export from multiple modules).

Since this package uses barrel files, it can lead to Next.js attempting to load client-specific scripts during SSR, resulting in errors or unintended behavior.

To mitigate this, add the following configuration to next.config.js. This setting tells Next.js to optimize the import of @geniux/google-drive-picker-react so that client-side modules are correctly handled as client-only, preventing SSR errors:

// next.config.js|mjs|ts
module.exports = {
    experimental: {
        optimizePackageImports: ['@geniux/google-drive-picker-react'],
    },
};

With this configuration, Next.js will avoid attempting to load client-side scripts server-side, ensuring the Google scripts and Picker functionality load properly when rendered on the client.

Options and Configurations

GoogleDrivePickerProvider Props

  • clientId (string): Google API client ID for OAuth.
  • apiKey (string): Google API key for Drive Picker.

useGoogleDrivePicker Options

  • allowMultiSelect (boolean): Allow multi-selection of files.
  • scopes (array of GoogleDriveScope): OAuth scopes for Google Drive access, defaults to ['https://www.googleapis.com/auth/drive.file'].

Types and Configuration Options

Refer to the types for detailed type definitions and additional configuration options.

Also, check the types in @geniux/google-drive-picker-core for more details on OAuth configurations.


License

MIT