Skip to content

Commit 400bfab

Browse files
author
sw-yx
committed
init
1 parent 3b5fac5 commit 400bfab

File tree

4 files changed

+4504
-1907
lines changed

4 files changed

+4504
-1907
lines changed

package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"version": "0.3.0",
44
"private": true,
55
"dependencies": {
6-
"netlify-lambda": "^0.4.0",
76
"react": "^16.3.1",
87
"react-dom": "^16.3.1",
9-
"react-scripts": "1.1.4"
8+
"react-scripts": "^2.0.0-next.a671462c"
109
},
1110
"scripts": {
1211
"start": "react-scripts start",
@@ -23,5 +22,21 @@
2322
"^/\\.netlify/functions": ""
2423
}
2524
}
25+
},
26+
"devDependencies": {
27+
"@babel/plugin-proposal-class-properties": "^7.0.0-rc.2",
28+
"@babel/plugin-transform-object-assign": "^7.0.0-rc.2"
29+
},
30+
"browserslist": {
31+
"development": [
32+
"last 2 chrome versions",
33+
"last 2 firefox versions",
34+
"last 2 edge versions"
35+
],
36+
"production": [
37+
">0.25%",
38+
"not op_mini all",
39+
"ie 11"
40+
]
2641
}
2742
}

src/App.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
import React, { Component } from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
1+
import React, { Component } from "react";
2+
import logo from "./logo.svg";
3+
import "./App.css";
44

55
class LambdaDemo extends Component {
66
constructor(props) {
77
super(props);
8-
this.state = {loading: false, msg: null};
8+
this.state = { loading: false, msg: null };
99
}
1010

11-
handleClick = (e) => {
11+
handleClick = e => {
1212
e.preventDefault();
1313

14-
this.setState({loading: true});
15-
fetch('/.netlify/functions/hello')
14+
this.setState({ loading: true });
15+
fetch("/.netlify/functions/hello")
1616
.then(response => response.json())
17-
.then(json => this.setState({loading: false, msg: json.msg}));
18-
}
17+
.then(
18+
json =>
19+
console.log({ json }) ||
20+
this.setState({ loading: false, msg: json.msg })
21+
);
22+
};
1923

2024
render() {
21-
const {loading, msg} = this.state;
25+
const { loading, msg } = this.state;
2226

23-
return <p>
24-
<button onClick={this.handleClick}>{loading ? 'Loading...' : 'Call Lambda'}</button><br/>
25-
<span>{msg}</span>
26-
</p>
27+
return (
28+
<p>
29+
<button onClick={this.handleClick}>
30+
{loading ? "Loading..." : "Call Lambda"}
31+
</button>
32+
<br />
33+
<span>{msg}</span>
34+
</p>
35+
);
2736
}
2837
}
2938

@@ -38,7 +47,7 @@ class App extends Component {
3847
<p className="App-intro">
3948
To get started, edit <code>src/App.js</code> and save to reload.
4049
</p>
41-
<LambdaDemo/>
50+
<LambdaDemo />
4251
</div>
4352
);
4453
}

src/lambda/hello.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
const test = {
2+
foo: "bar",
3+
bar: 1
4+
};
15
export function handler(event, context, callback) {
2-
console.log(event)
6+
console.log(event);
37
callback(null, {
48
statusCode: 200,
5-
body: JSON.stringify({msg: "Hello, World!"})
6-
})
9+
body: JSON.stringify({ msg: "Hello, World!", ...test })
10+
});
711
}

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