Skip to content

Commit 72a7ceb

Browse files
committed
Add demo of calling a lambda
1 parent 6bbb842 commit 72a7ceb

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"netlify-lambda": "^0.0.1",
6+
"netlify-lambda": "^0.1.0",
77
"react": "^16.1.0",
88
"react-dom": "^16.1.0",
99
"react-scripts": "1.0.17"

src/App.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@ import React, { Component } from 'react';
22
import logo from './logo.svg';
33
import './App.css';
44

5+
class LambdaDemo extends Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {loading: false, msg: null};
9+
}
10+
11+
handleClick = (e) => {
12+
e.preventDefault();
13+
14+
this.setState({loading: true});
15+
fetch('/.netlify/functions/hello')
16+
.then(response => response.json())
17+
.then(json => this.setState({loading: false, msg: json.msg}));
18+
}
19+
20+
render() {
21+
const {loading, msg} = this.state;
22+
23+
return <p>
24+
<button onClick={this.handleClick}>{loading ? 'Loading...' : 'Call Lambda'}</button><br/>
25+
<span>{msg}</span>
26+
</p>
27+
}
28+
}
29+
530
class App extends Component {
631
render() {
732
return (
@@ -13,6 +38,7 @@ class App extends Component {
1338
<p className="App-intro">
1439
To get started, edit <code>src/App.js</code> and save to reload.
1540
</p>
41+
<LambdaDemo/>
1642
</div>
1743
);
1844
}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,9 +4217,9 @@ negotiator@0.6.1:
42174217
version "0.6.1"
42184218
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
42194219

4220-
netlify-lambda@^0.0.1:
4221-
version "0.0.1"
4222-
resolved "https://registry.yarnpkg.com/netlify-lambda/-/netlify-lambda-0.0.1.tgz#3c4967afd0252ccb60041b8c9223f0f4faf2a731"
4220+
netlify-lambda@^0.1.0:
4221+
version "0.1.0"
4222+
resolved "https://registry.yarnpkg.com/netlify-lambda/-/netlify-lambda-0.1.0.tgz#7993b7dff0fa93b1b99576d453e7dd79e78790d5"
42234223
dependencies:
42244224
babel-plugin-transform-class-properties "^6.24.1"
42254225
babel-plugin-transform-object-assign "^6.22.0"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy