Connect with us

Tech

How to convert Google Sheets to REST API and use it in React application

Avatar

Published

on


Posting data to the API has never been easier. But have you ever used React to post form data to Google Sheets? If not, this tutorial is for you.

Today, I’ll show you how to POST form data from React to a Google spreadsheet like REST API.

First, create a React app.

To get started, you can use create-react-app to set up your React app.

Simply type npx create-react-app react-googlesheets to set up your project directory.

How to install the folder structure Semantic UI

Semantic UI is a framework used to design and develop beautiful and responsive layouts. It has components such as buttons, containers, lists, and inputs.

To install the Semantic UI in your React application, use the following command:

npm install semantic-ui-react semantic-ui-css

Once the installation is complete, open the index.js file and import the one at the top.

import’semantic-ui-css / semantic.min.css’

Then run the app using the command npmstart.

Let’s create some input boxes

Create forms and input boxes to get input such as name, age, salary, hobbies from the React app.

Here, Buttons, Form, Container and Header are imported from the semantic-ui-react library to create form fields.

import React, {Component} from’react’import {Button, Form, Container, Header} from’semantic-ui-react’ import’./ App.css’; Export default class Appextends Component {render () {return (

Respond to Google Sheets!



















)}} App.js.form {width: 500px;} .container {padding: 20px} App.css

This is what it looks like:

Output form

The UI is now complete. Let’s add some features.

First, let’s create the states of the four form fields in the constructor.

import React, {Component} from’react’import {Button, Form, Container, Header} from’semantic-ui-react’ import’./ App.css’; export default class App extends Component {Constructor (props) {super (Props) this.state = {name:”, age:”, salary:”, hobby:”}} changeHandler = (e) => {this.setState ({[e.target.name] : E.target.value})} submitHandler = e => {e.preventDefault (); console.log (this.state);} render () {const {name, age, salary, hobbies} = this.state;

return(



















participate

)}}

Here we have four form fields and their respective states. There is also a changeHandler method for tracking changes in input values.

Let’s decompose the state with the render method and add those values ​​to the input value attribute (line *).

The last thing you need is an onSubmit handler. In the form tag, add the onSubmit event and assign the submitHandler method.

Fill out the form[送信]Click. The entered data is displayed on the console.

There is a form to get your name, age, salary and hobbies and record them on the console.

How to post data to Google Sheets

Let’s change Google Sheets to REST API.

Post the data as a REST API to Google Sheets. To do this, you need to have Axios installed. This is a library that you can use to send requests to the API, similar to fetching.

[ファイル],[新規],[スプレッドシート]Click to open a new spreadsheet.

Save the sheet with a name of your choice.

Click the share button at the top right of the screen to edit the publish permissions.

Copy the link and go to https://sheet.best/ to create a free account.

Create a new connection and copy the URL from Google Sheets[接続URL]Paste it in the box.

Click Connect. You will be redirected to the connection page. Here you can see all the connections. Click the new connection details.

Copy the connection URL. This URL will be used as an endpoint for sending POST requests.

Now let’s install Axios. Type npm install axios in the terminal to install the package.

Once installed, import it to the beginning of the file. Make a POST request with the submitHandler function.

submitHandler = e => {e.preventDefault (); console.log (this.state); axios.post (‘url’, this.state) .then (response => {console.log (response);})} submitHandler method

Replace the submitHandler function with the above code. Here, I’m using Axios to post the data to a URL and using the .then keyword to return a response in the console.

Paste the CONNECTION URL endpoint that you copied from sheet.best and replace it with the URL of axios.post (‘url’).

submitHandler = e => {e.preventDefault (); console.log (this.state); axios.post (‘https://sheet.best/api/sheets/a6e67deb-2f00-43c3-89d3-b331341d53ed’, this .state) .then (response => {console.log (response);})} submitHandler function

Then open Google Sheets and fill in the first column for Name, Age, Salary, Hobbies. Please fill in carefully. If you do not fill it out, it will not work. It must be case sensitive.

Add fields for name, age, salary, hobbies

Then run the React app and fill in the input fields. You can see that the data is entered in the Google spreadsheet one by one.

React form sample fields

It’s all people. Now you know how to convert Google Sheets to REST API. You can now use the React application to save your data to Google Sheets.

Alternatively, you can find the code on Github and experiment with it. Happy learning.

What Are The Main Benefits Of Comparing Car Insurance Quotes Online

LOS ANGELES, CA / ACCESSWIRE / June 24, 2020, / Compare-autoinsurance.Org has launched a new blog post that presents the main benefits of comparing multiple car insurance quotes. For more info and free online quotes, please visit https://compare-autoinsurance.Org/the-advantages-of-comparing-prices-with-car-insurance-quotes-online/ The modern society has numerous technological advantages. One important advantage is the speed at which information is sent and received. With the help of the internet, the shopping habits of many persons have drastically changed. The car insurance industry hasn't remained untouched by these changes. On the internet, drivers can compare insurance prices and find out which sellers have the best offers. View photos The advantages of comparing online car insurance quotes are the following: Online quotes can be obtained from anywhere and at any time. Unlike physical insurance agencies, websites don't have a specific schedule and they are available at any time. Drivers that have busy working schedules, can compare quotes from anywhere and at any time, even at midnight. Multiple choices. Almost all insurance providers, no matter if they are well-known brands or just local insurers, have an online presence. Online quotes will allow policyholders the chance to discover multiple insurance companies and check their prices. Drivers are no longer required to get quotes from just a few known insurance companies. Also, local and regional insurers can provide lower insurance rates for the same services. Accurate insurance estimates. Online quotes can only be accurate if the customers provide accurate and real info about their car models and driving history. Lying about past driving incidents can make the price estimates to be lower, but when dealing with an insurance company lying to them is useless. Usually, insurance companies will do research about a potential customer before granting him coverage. Online quotes can be sorted easily. Although drivers are recommended to not choose a policy just based on its price, drivers can easily sort quotes by insurance price. Using brokerage websites will allow drivers to get quotes from multiple insurers, thus making the comparison faster and easier. For additional info, money-saving tips, and free car insurance quotes, visit https://compare-autoinsurance.Org/ Compare-autoinsurance.Org is an online provider of life, home, health, and auto insurance quotes. This website is unique because it does not simply stick to one kind of insurance provider, but brings the clients the best deals from many different online insurance carriers. In this way, clients have access to offers from multiple carriers all in one place: this website. On this site, customers have access to quotes for insurance plans from various agencies, such as local or nationwide agencies, brand names insurance companies, etc. "Online quotes can easily help drivers obtain better car insurance deals. All they have to do is to complete an online form with accurate and real info, then compare prices", said Russell Rabichev, Marketing Director of Internet Marketing Company. CONTACT: Company Name: Internet Marketing CompanyPerson for contact Name: Gurgu CPhone Number: (818) 359-3898Email: [email protected]: https://compare-autoinsurance.Org/ SOURCE: Compare-autoinsurance.Org View source version on accesswire.Com:https://www.Accesswire.Com/595055/What-Are-The-Main-Benefits-Of-Comparing-Car-Insurance-Quotes-Online View photos



picture credit

ExBUlletin

to request, modification Contact us at Here or [email protected]