|
| 1 | + |
| 2 | +# React JS Starter app |
| 3 | + |
| 4 | +A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES |
| 5 | + |
| 6 | +JUST THE UI |
| 7 | +Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project. |
| 8 | + |
| 9 | +VIRTUAL DOM |
| 10 | +React abstracts away the DOM from you, giving a simpler programming model and better performance. React can also render on the server using Node, and it can power native apps using React Native. |
| 11 | + |
| 12 | +DATA FLOW |
| 13 | +React implements one-way reactive data flow which reduces boilerplate and is easier to reason about than traditional data binding. |
| 14 | +Topics |
| 15 | +================ |
| 16 | +- React JS components |
| 17 | +- React js event handeling |
| 18 | +- Parent Child Components |
| 19 | +- Todo app using React |
| 20 | +- Cart app using React |
| 21 | + |
| 22 | +Application setup |
| 23 | +============== |
| 24 | +- App require NPM Node installed |
| 25 | + |
| 26 | +```Javascript |
| 27 | +mkdir DemoApp |
| 28 | +cd DemoApp |
| 29 | +npm init |
| 30 | +or just add this package json |
| 31 | +{ |
| 32 | + "name": "HelloWorld", |
| 33 | + "version": "0.0.1", |
| 34 | + "description": "HelloWorld", |
| 35 | + "main": "dist/index.js", |
| 36 | + "engines": { |
| 37 | + "node": ">=0.10.32" |
| 38 | + }, |
| 39 | + "scripts": { |
| 40 | + "build": "webpack --progress --profile --colors", |
| 41 | + "watch": "webpack-dev-server --hot --inline --progress --colors", |
| 42 | + "test": "echo \"No unit tests and e2e tests yet\" && exit 1" |
| 43 | + }, |
| 44 | + "repository": { |
| 45 | + "type": "git", |
| 46 | + "url": "" |
| 47 | + }, |
| 48 | + "bugs": { |
| 49 | + "url": "" |
| 50 | + }, |
| 51 | + "author": "Richard LOPES", |
| 52 | + "license": "MIT", |
| 53 | + "homepage": "", |
| 54 | + "dependencies": { |
| 55 | + "babel-preset-react": "^6.5.0", |
| 56 | + "babel-runtime": "5.6.18", |
| 57 | + "html-webpack-plugin": "^2.15.0", |
| 58 | + "react": "^15.0.0", |
| 59 | + "react-dom": "^15.0.0" |
| 60 | + }, |
| 61 | + "devDependencies": { |
| 62 | + "babel-core": "5.6.18", |
| 63 | + "babel-loader": "5.3.1", |
| 64 | + "html-webpack-plugin": "1.6.0", |
| 65 | + "webpack": "1.12.1", |
| 66 | + "webpack-dev-server": "1.12.1" |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +// In webpack.config.js |
| 71 | +var HtmlWebpackPlugin = require('html-webpack-plugin') |
| 72 | +var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({ |
| 73 | + template: __dirname + '/app/index.html', |
| 74 | + filename: 'index.html', |
| 75 | + inject: 'body' |
| 76 | +}); |
| 77 | +module.exports = { |
| 78 | + entry: [ |
| 79 | + './app/index.js' |
| 80 | + ], |
| 81 | + output: { |
| 82 | + path: __dirname + '/dist', |
| 83 | + filename: "index_bundle.js" |
| 84 | + }, |
| 85 | + module: { |
| 86 | + loaders: [ |
| 87 | + {test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"} |
| 88 | + ] |
| 89 | + }, |
| 90 | + plugins: [HTMLWebpackPluginConfig] |
| 91 | +}; |
| 92 | + |
| 93 | +``` |
| 94 | + |
| 95 | + |
| 96 | +React JS |
| 97 | +==================== |
| 98 | +<a name="README">[<img src="https://avatars2.githubusercontent.com/reactjs-cn" width="50px" height="50px" />](https://github.com/kumartarun/React-JS-Starter-apps.git)</a> |
| 99 | + |
| 100 | +Creating components |
| 101 | +==================== |
| 102 | +```Javascript |
| 103 | +var HelloWorld = React.createClass({ |
| 104 | + render: function() { |
| 105 | + return ( |
| 106 | + <div> |
| 107 | + <h1>Hello World</h1> |
| 108 | + <p>This is some text</p> |
| 109 | + </div> |
| 110 | + ); |
| 111 | + } |
| 112 | + }); |
| 113 | + |
| 114 | + React.render(<HelloWorld />, document.body); |
| 115 | +``` |
| 116 | + |
| 117 | +Event Handeling |
| 118 | +==================== |
| 119 | +```Javascript |
| 120 | + |
| 121 | + var Checkbox = React.createClass({ |
| 122 | + getInitialState: function() { |
| 123 | + return {checked: true} |
| 124 | + }, |
| 125 | + handleCheck: function() { |
| 126 | + this.setState({checked: !this.state.checked}) |
| 127 | + }, |
| 128 | + render: function() { |
| 129 | + var msg; |
| 130 | + if(this.state.checked) { |
| 131 | + msg = "checked"; |
| 132 | + } |
| 133 | + else { |
| 134 | + msg = "unchecked"; |
| 135 | + } |
| 136 | + return ( |
| 137 | + |
| 138 | + <div> |
| 139 | + <div> |
| 140 | + <h1 class="container well">hello react</h1> |
| 141 | + |
| 142 | + <input type="checkbox" |
| 143 | + defaultChecked={this.state.checked} onChange={this.handleCheck}/> |
| 144 | + <p>This box is {msg}.</p> |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + ); |
| 148 | + } |
| 149 | + }); |
| 150 | + |
| 151 | + React.render(<Checkbox/>, |
| 152 | + document.getElementById('react-container')); |
| 153 | + |
| 154 | +`` |
| 155 | + |
| 156 | +Run the tutorial (each file is numbered) |
| 157 | +==================== |
| 158 | +```Terminal |
| 159 | +git clone https://github.com/kumartarun/React-JS-Starter-apps.git |
| 160 | +Run index.html files on any local server |
| 161 | +``` |
| 162 | + |
| 163 | +Contact |
| 164 | +==================== |
| 165 | +[<img src="https://s3-us-west-2.amazonaws.com/martinsocial/MARTIN2.png" />](http://gennexttraining.herokuapp.com/) |
| 166 | +[<img src="https://s3-us-west-2.amazonaws.com/martinsocial/github.png" />](https://github.com/tkssharma) |
| 167 | +[<img src="https://s3-us-west-2.amazonaws.com/martinsocial/mail.png" />](mailto:tarun.softengg@gmail.com) |
| 168 | +[<img src="https://s3-us-west-2.amazonaws.com/martinsocial/linkedin.png" />](https://www.linkedin.com/in/tkssharma) |
| 169 | +[<img src="https://s3-us-west-2.amazonaws.com/martinsocial/twitter.png" />](https://twitter.com/tkssharma) |
0 commit comments