All Projects → gglukmann → use-google-sheets

gglukmann / use-google-sheets

Licence: MIT license
📝 A React Hook for getting data from Google Sheets API v4

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to use-google-sheets

Gspread
Google Sheets Python API
Stars: ✭ 5,676 (+7468%)
Mutual labels:  google-sheets, google-sheets-api, google-sheets-api-v4
sheetful
The sheetiest REST API on the block.
Stars: ✭ 65 (-13.33%)
Mutual labels:  google-sheets, google-sheets-api
discord2sheet-bot
Discord bot that stores messages to Google Sheet.
Stars: ✭ 40 (-46.67%)
Mutual labels:  google-sheets, google-sheets-api-v4
Googlesheets
best code I've tested in Google Sheets
Stars: ✭ 109 (+45.33%)
Mutual labels:  google-sheets
Robinhood Google Sheets
Robinhood Custom Functions for Google Sheets 📈
Stars: ✭ 117 (+56%)
Mutual labels:  google-sheets
Gspread Pandas
A package to easily open an instance of a Google spreadsheet and interact with worksheets through Pandas DataFrames.
Stars: ✭ 226 (+201.33%)
Mutual labels:  google-sheets
code
Google Apps Script - Code Snippets 👩🏻‍💻
Stars: ✭ 108 (+44%)
Mutual labels:  google-sheets
Node Google Spreadsheet
Google Sheets API (v4) wrapper for Node.js
Stars: ✭ 1,369 (+1725.33%)
Mutual labels:  google-sheets
Retrosheet
Turn Google Spreadsheet to JSON endpoint (for Android and JVM) for FREE (100%)
Stars: ✭ 245 (+226.67%)
Mutual labels:  google-sheets
Exportsheetdata
Add-on for Google Sheets that allows sheets to be exported as JSON or XML.
Stars: ✭ 170 (+126.67%)
Mutual labels:  google-sheets
Auto Youtube Subscription Playlist 2
Script automatically adds videos to playlists from Youtube channels and/or subscriptions (Youtube Collections alternative).
Stars: ✭ 136 (+81.33%)
Mutual labels:  google-sheets
Gspread Dataframe
Read/write Google spreadsheets using pandas DataFrames
Stars: ✭ 118 (+57.33%)
Mutual labels:  google-sheets
Flutter2googlesheets Demo
A Demo application📱 which stores User feedback from 💙Flutter application into Google Sheets🗎 using Google AppScript.
Stars: ✭ 228 (+204%)
Mutual labels:  google-sheets
Df2gspread
Manage Google Spreadsheets in Pandas DataFrame with Python
Stars: ✭ 114 (+52%)
Mutual labels:  google-sheets
react-hooks-lifecycle
⚛️ 🪝 ⏳ React hooks lifecycle diagram: Functional components lifecycle explained
Stars: ✭ 194 (+158.67%)
Mutual labels:  react-hooks
Importjson
Import JSON into Google Sheets, this library adds various ImportJSON functions to your spreadsheet
Stars: ✭ 1,705 (+2173.33%)
Mutual labels:  google-sheets
Googlesheets4
Google Spreadsheets R API (reboot of the googlesheets package)
Stars: ✭ 232 (+209.33%)
Mutual labels:  google-sheets
Spreadsheetfs
Use Google Sheets as a Filesystem to get Unlimited Free Cloud Storage
Stars: ✭ 137 (+82.67%)
Mutual labels:  google-sheets
Gesi
Google Sheets ESI Add-on
Stars: ✭ 135 (+80%)
Mutual labels:  google-sheets
Localizable Sheet Script
A Google Sheets script that will take a sheet in a specific format and return iOS and Android localization files.
Stars: ✭ 197 (+162.67%)
Mutual labels:  google-sheets

useGoogleSheets

A React Hook wrapper library for google-sheets-mapper for getting data from Google Sheets API v4

Minified file size License: MIT NPM version


Installation

Package can be added using yarn:

yarn add use-google-sheets

Or, use NPM:

npm install use-google-sheets

UMD build available on unpkg.


Usage

  1. Go to Google Cloud Console to get API key for Google Sheets API.
  2. Create a Google Sheet and add some data. See example sheet.
  3. Share it with "Anyone with this link can view".
  4. Get sheet id from url of the sheet.
https://docs.google.com/spreadsheets/d/[THIS-IS-THE-SHEET-ID]/
  1. I suggest adding API key and sheet id to .env file

Examples

Get data from all sheets inside the spreadsheet

import useGoogleSheets from 'use-google-sheets';

const App = () => {
  const { data, loading, error } = useGoogleSheets({
    apiKey: process.env.REACT_APP_GOOGLE_API_KEY,
    sheetId: process.env.REACT_APP_GOOGLE_SHEETS_ID,
  });

  if (loading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error!</div>;
  }

  return <div>{JSON.stringify(data)}</div>;
};

Get data from specific sheets inside the spreadsheet

Don't use single quotes on sheet names, they will be removed because when using space in sheet name it will be returned wrapped with single quotes and plugin will remove them for clean string id.

import useGoogleSheets from 'use-google-sheets';

const App = () => {
  const { data, loading, error } = useGoogleSheets({
    apiKey: process.env.REACT_APP_GOOGLE_API_KEY,
    sheetId: process.env.REACT_APP_GOOGLE_SHEETS_ID,
    sheetsOptions: [{ id: 'Sheet1' }],
  });

  if (loading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error!</div>;
  }

  return <div>{JSON.stringify(data)}</div>;
};

Refetch data from all sheets inside the spreadsheet

import useGoogleSheets from 'use-google-sheets';

const App = () => {
  const { data, loading, error, refetch } = useGoogleSheets({
    apiKey: process.env.REACT_APP_GOOGLE_API_KEY,
    sheetId: process.env.REACT_APP_GOOGLE_SHEETS_ID,
  });

  if (loading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error!</div>;
  }

  return (
    <div>
      <div>{JSON.stringify(data)}</div>

      <button onClick={refetch}>Refetch</button>
    </div>
  );
};

API Documentation

The useGoogleSheets hook takes an object with three properties:

Name Value
apiKey string
sheetId string
sheetsOptions array
  • apiKey is a Google Sheets API v4 key from Google Cloud Console.
  • sheetId is the id of the sheet.
  • sheetsOptions is an array of specific objects { id, headerRowIndex }. Can be left out then it will fallback to all sheets inside the spreadsheet and use first row from sheet as header.

Exposed Data

The hook produces an HookState object:

const { data, loading, error, refetch, called } = useGoogleSheets({
  apiKey,
  sheetId,
});
Name Value
data array
loading boolean
error null or object
refetch function
called boolean
  • data is an array of mapped data objects.
[
  {
    id: 'Sheet1',
    data: [
      { key: 'language', value: 'et' },
      { key: 'title', value: 'Test sheet' },
    ],
  },
];
  • loading lets you know whether data is being fetched and mapped.
  • error lets you know when there is something wrong. It returns an error object where you can get specific error properties from error.response
{
  status: '404',
  statusText: '',
  url: 'https://sheets.googleapis.com/v4/spreadsheets/...',
}

Migration from v1 to v2

  • Change sheetsNames array of string to sheetsOptions array of objects with { id: 'sheetName' }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].