Skip to content

Commit f9993e2

Browse files
committed
Initialization Lifecycle Methods Implemented
0 parents  commit f9993e2

File tree

7 files changed

+117
-0
lines changed

7 files changed

+117
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Whitespace-only changes.

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "react-default",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "webpack-dev-server --content-base static --inline",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"express": "^4.15.3",
14+
"react": "^15.5.4",
15+
"react-dom": "^15.5.4"
16+
},
17+
"devDependencies": {
18+
"babel-cli": "^6.24.1",
19+
"babel-core": "^6.25.0",
20+
"babel-loader": "^7.0.0",
21+
"babel-preset-es2015": "^6.24.1",
22+
"babel-preset-react": "^6.24.1",
23+
"webpack": "^2.6.1"
24+
}
25+
}

server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const express = require("express");
2+
const app = express();
3+
4+
app.use ( express.static("static/") );
5+
6+
app.listen(3000, function() {
7+
console.log("Listening on port 3000")
8+
});

src/app.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
5+
class App extends React.Component{
6+
7+
constructor(props){
8+
super(props);
9+
10+
11+
//getInitialState has moved to constructor
12+
console.log("constructor() is called");
13+
this.state = {value: props.initialValue};
14+
}
15+
16+
render(){
17+
return(
18+
<div>The value is: {this.state.value}</div>
19+
);
20+
}
21+
22+
23+
}
24+
25+
App.defaultProps = { initialValue: 0 };
26+
App.propTypes = { initialValue: React.PropTypes.number };
27+
28+
var app = <App/>;
29+
30+
var node = document.getElementById("app");
31+
32+
ReactDOM.render(app, node);

static/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>React</title>
5+
</head>
6+
<body>
7+
<div id="app"></div>
8+
<script src="bundle.js"></script>
9+
</body>
10+
</html>

webpack.config.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var webpack = require('webpack');
2+
var path = require('path');
3+
4+
var BUILD_DIR = path.resolve(__dirname, 'static/');
5+
var APP_DIR = path.resolve(__dirname, 'src/');
6+
7+
var config = {
8+
9+
entry : APP_DIR + '/app.jsx',
10+
11+
output: {
12+
path: BUILD_DIR,
13+
filename: 'bundle.js'
14+
},
15+
16+
module : {
17+
loaders : [
18+
{
19+
test : /\.jsx?/,
20+
include : APP_DIR,
21+
loader : "babel-loader",
22+
query: {
23+
presets: ['react', 'es2015']
24+
}
25+
}
26+
]
27+
},
28+
29+
resolve: {
30+
// you can now require or import('file') instead of require('file.js or file.jsx')
31+
extensions: ['.js', '.jsx']
32+
}
33+
34+
35+
};
36+
37+
module.exports = config;
38+
39+
40+
41+

0 commit comments

Comments
 (0)