├── _config.yml ├── .gitattributes ├── examples ├── basic-react-example-lifecycle │ ├── README.md │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── index.html │ ├── src │ │ ├── index.js │ │ ├── App.test.js │ │ ├── App.js │ │ └── Child.js │ ├── .gitignore │ └── package.json ├── basic-react-example-state │ ├── README.md │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── index.html │ ├── src │ │ ├── index.js │ │ ├── App.test.js │ │ ├── FunctionalComponent.js │ │ ├── App.js │ │ └── ClassComponent.js │ ├── .gitignore │ └── package.json ├── react-redux-webpack-client-server │ ├── jest │ ├── README.md │ ├── src │ │ ├── index.css │ │ ├── other.js │ │ ├── actions │ │ │ ├── types.js │ │ │ └── index.js │ │ ├── App.css │ │ ├── images │ │ │ └── rPI-400x400.jpg │ │ ├── tempPolyfills.js │ │ ├── Intro.js │ │ ├── App.css.js │ │ ├── reducers │ │ │ ├── index.js │ │ │ └── commentsReducer.js │ │ ├── setupTests.js │ │ ├── App.test.js │ │ ├── TestingSSR.js │ │ ├── Intro.test.js │ │ ├── index.js │ │ └── App.js │ ├── public │ │ ├── main-50be1c23bed016f8c72b.css │ │ ├── favicon.ico │ │ ├── main-bundle.js.br │ │ ├── main-bundle.js.gz │ │ ├── other-bundle.js.br │ │ ├── other-bundle.js.gz │ │ ├── images │ │ │ └── rPI-400x400.jpg │ │ ├── vendors~main-bundle.js.br │ │ ├── vendors~main-bundle.js.gz │ │ ├── manifest.json │ │ ├── template.html │ │ └── other-bundle.js │ ├── server │ │ ├── test.js │ │ ├── index.js │ │ ├── .gitignore │ │ ├── package.json │ │ ├── BasicController.js │ │ └── server.js │ ├── config │ │ ├── jest │ │ │ ├── tempPolyfills.js │ │ │ ├── setupTests.js │ │ │ └── jest.config.json │ │ ├── webpack.config.dev.client.js │ │ ├── webpack.config.prod.server.js │ │ ├── webpack.config.dev.server.js │ │ ├── webpack.config.prod.js │ │ └── webpack.config.js │ ├── .babelrc │ ├── .gitignore │ └── package.json ├── react-redux-webpack-client │ ├── README.md │ ├── src │ │ ├── other.js │ │ ├── actions │ │ │ ├── types.js │ │ │ └── index.js │ │ ├── tempPolyfills.js │ │ ├── Intro.js │ │ ├── reducers │ │ │ ├── index.js │ │ │ └── commentsReducer.js │ │ ├── setupTests.js │ │ ├── App.test.js │ │ ├── Intro.test.js │ │ ├── App.js │ │ └── index.js │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ ├── otherbundle.js │ │ ├── template.html │ │ └── index.html │ ├── .babelrc │ ├── config │ │ ├── webpack.config.dev.js │ │ ├── webpack.config.prod.js │ │ └── webpack.config.js │ ├── .gitignore │ └── package.json ├── basic-react-example[map-with-key] │ ├── README.md │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── index.html │ ├── src │ │ ├── index.js │ │ ├── App.test.js │ │ └── App.js │ ├── .gitignore │ └── package.json ├── react-redux-webpack-client-server-scripts │ ├── jest │ ├── README.md │ ├── src │ │ ├── index.css │ │ ├── other.js │ │ ├── actions │ │ │ ├── types.js │ │ │ └── index.js │ │ ├── App.css │ │ ├── images │ │ │ └── rPI-400x400.jpg │ │ ├── tempPolyfills.js │ │ ├── Intro.js │ │ ├── App.css.js │ │ ├── reducers │ │ │ ├── index.js │ │ │ └── commentsReducer.js │ │ ├── setupTests.js │ │ ├── App.test.js │ │ ├── TestingSSR.js │ │ ├── Intro.test.js │ │ ├── index.js │ │ └── App.js │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── template.html │ ├── server │ │ ├── test.js │ │ ├── index.js │ │ ├── .gitignore │ │ ├── package.json │ │ ├── BasicController.js │ │ └── server.js │ ├── config │ │ ├── jest │ │ │ ├── tempPolyfills.js │ │ │ ├── setupTests.js │ │ │ └── jest.config.json │ │ ├── webpack.config.dev.server.js │ │ ├── webpack.config.prod.server.js │ │ ├── webpack.config.dev.client.js │ │ ├── webpack.config.prod.client.js │ │ └── webpack.config.js │ ├── .babelrc │ ├── .gitignore │ └── package.json └── basic-webpack[default] │ ├── src │ ├── other.js │ ├── index.js │ └── app.js │ ├── dist │ ├── index.html │ └── bundle.js │ ├── .gitignore │ ├── webpack.config.js │ └── package.json ├── images ├── npm-test.png ├── comparative.png ├── eject-comp.png ├── jest-basic.png ├── logger-logs.png ├── curl-response.png ├── jest-coverage.png ├── npm-coverage.png ├── updating-DOM.png ├── cssInJs-trends.png ├── curl-response-br.png ├── map-array-warning.png ├── missing-css-loader.png ├── unit-test-behavior.png ├── unit-test-snapshot.png ├── redux-devTools-state.png ├── unit-test-behavior-1.png ├── unit-test-redux-app.png ├── unit-test-redux-app1.png ├── unit-test-redux-app2.png ├── unit-test-redux-app3.png ├── unit-test-structure.png ├── unit-test-diff-snapshot.png ├── webpack-bundle-analyzer.png ├── map-array-duplicated-key.png ├── react-devTools-propTypes.png ├── react-devTools-reactRouter.png ├── redux-devTools-state-test.png ├── webpack-dev-client-server.png ├── webpack-network-requests.png ├── redux-devTools-state-dispatch.png └── webpackDevMiddleware-reCompiles-express.png ├── .whitesource ├── notesToPlace.md ├── .gitignore ├── greenkeeper.json ├── LICENSE ├── 00_1_intro_JS.md ├── 06_lifecycle-events.md ├── 07_conditional-rendering.md ├── 04_methods.md ├── notesToPlace_primitive-and-reference-types.md ├── 01_1_elements.md ├── 00_3_intro_es2015.md ├── README.md ├── 00_2_intro_JS-patterns.md ├── 01_0_starting.md ├── 12_full-client-app.md ├── 01_2_JS-module-systems.md ├── 00_0_intro.md ├── 02_0_components.md ├── 03_local-state.md ├── 02_1_props.md └── 05_controlled-components.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=JavaScript -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/jest: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/jest: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/src/other.js: -------------------------------------------------------------------------------- 1 | console.log('other.js'); 2 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 30px; 3 | } 4 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/other.js: -------------------------------------------------------------------------------- 1 | console.log('I´m the other entry!'); 2 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/other.js: -------------------------------------------------------------------------------- 1 | console.log('I´m the other entry!'); 2 | -------------------------------------------------------------------------------- /images/npm-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/npm-test.png -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 30px; 3 | } 4 | -------------------------------------------------------------------------------- /images/comparative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/comparative.png -------------------------------------------------------------------------------- /images/eject-comp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/eject-comp.png -------------------------------------------------------------------------------- /images/jest-basic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/jest-basic.png -------------------------------------------------------------------------------- /images/logger-logs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/logger-logs.png -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/other.js: -------------------------------------------------------------------------------- 1 | console.log('I´m the other entry!'); 2 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/actions/types.js: -------------------------------------------------------------------------------- 1 | export const FETCH_COMMENTS = 'FETCH_COMMENTS'; 2 | -------------------------------------------------------------------------------- /images/curl-response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/curl-response.png -------------------------------------------------------------------------------- /images/jest-coverage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/jest-coverage.png -------------------------------------------------------------------------------- /images/npm-coverage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/npm-coverage.png -------------------------------------------------------------------------------- /images/updating-DOM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/updating-DOM.png -------------------------------------------------------------------------------- /images/cssInJs-trends.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/cssInJs-trends.png -------------------------------------------------------------------------------- /images/curl-response-br.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/curl-response-br.png -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/actions/types.js: -------------------------------------------------------------------------------- 1 | export const FETCH_COMMENTS = 'FETCH_COMMENTS'; 2 | -------------------------------------------------------------------------------- /images/map-array-warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/map-array-warning.png -------------------------------------------------------------------------------- /images/missing-css-loader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/missing-css-loader.png -------------------------------------------------------------------------------- /images/unit-test-behavior.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-behavior.png -------------------------------------------------------------------------------- /images/unit-test-snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-snapshot.png -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/actions/types.js: -------------------------------------------------------------------------------- 1 | export const FETCH_COMMENTS = 'FETCH_COMMENTS'; 2 | -------------------------------------------------------------------------------- /images/redux-devTools-state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/redux-devTools-state.png -------------------------------------------------------------------------------- /images/unit-test-behavior-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-behavior-1.png -------------------------------------------------------------------------------- /images/unit-test-redux-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-redux-app.png -------------------------------------------------------------------------------- /images/unit-test-redux-app1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-redux-app1.png -------------------------------------------------------------------------------- /images/unit-test-redux-app2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-redux-app2.png -------------------------------------------------------------------------------- /images/unit-test-redux-app3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-redux-app3.png -------------------------------------------------------------------------------- /images/unit-test-structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-structure.png -------------------------------------------------------------------------------- /images/unit-test-diff-snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/unit-test-diff-snapshot.png -------------------------------------------------------------------------------- /images/webpack-bundle-analyzer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/webpack-bundle-analyzer.png -------------------------------------------------------------------------------- /images/map-array-duplicated-key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/map-array-duplicated-key.png -------------------------------------------------------------------------------- /images/react-devTools-propTypes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/react-devTools-propTypes.png -------------------------------------------------------------------------------- /images/react-devTools-reactRouter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/react-devTools-reactRouter.png -------------------------------------------------------------------------------- /images/redux-devTools-state-test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/redux-devTools-state-test.png -------------------------------------------------------------------------------- /images/webpack-dev-client-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/webpack-dev-client-server.png -------------------------------------------------------------------------------- /images/webpack-network-requests.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/webpack-network-requests.png -------------------------------------------------------------------------------- /examples/basic-webpack[default]/src/index.js: -------------------------------------------------------------------------------- 1 | const app = require('./app.js'); 2 | console.log('index.js'); 3 | 4 | app.someFunction(); 5 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/main-50be1c23bed016f8c72b.css: -------------------------------------------------------------------------------- 1 | h1{font-size:20px}.rPi{border:1px solid #000}body{margin:30px} -------------------------------------------------------------------------------- /images/redux-devTools-state-dispatch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/redux-devTools-state-dispatch.png -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/App.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | font-size: 20px; 3 | } 4 | 5 | .rPi { 6 | border: 1px solid black; 7 | } 8 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/App.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | font-size: 20px; 3 | } 4 | 5 | .rPi { 6 | border: 1px solid black; 7 | } 8 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/dist/index.html: -------------------------------------------------------------------------------- 1 | 2 |

Testing Basic Webpack Conf...!

3 | 4 | 5 | -------------------------------------------------------------------------------- /images/webpackDevMiddleware-reCompiles-express.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/images/webpackDevMiddleware-reCompiles-express.png -------------------------------------------------------------------------------- /examples/basic-react-example-state/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/basic-react-example-state/public/favicon.ico -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client/public/favicon.ico -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/basic-react-example-lifecycle/public/favicon.ico -------------------------------------------------------------------------------- /.whitesource: -------------------------------------------------------------------------------- 1 | { 2 | "generalSettings": { 3 | "shouldScanRepo": true 4 | }, 5 | "checkRunSettings": { 6 | "vulnerableCheckRunConclusionLevel": "failure" 7 | } 8 | } -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/basic-react-example[map-with-key]/public/favicon.ico -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/favicon.ico -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react"], 3 | "plugins": ["@babel/plugin-proposal-class-properties"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/main-bundle.js.br: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/main-bundle.js.br -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/main-bundle.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/main-bundle.js.gz -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server-scripts/public/favicon.ico -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/other-bundle.js.br: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/other-bundle.js.br -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/other-bundle.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/other-bundle.js.gz -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/images/rPI-400x400.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/src/images/rPI-400x400.jpg -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/images/rPI-400x400.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/images/rPI-400x400.jpg -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render(< App />, document.getElementById('root')); -------------------------------------------------------------------------------- /examples/basic-react-example-state/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render(, document.getElementById('root')); 6 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/src/app.js: -------------------------------------------------------------------------------- 1 | console.log('app.js'); 2 | 3 | // exports.fn is a shortcut of module.exports.fn 4 | exports.someFunction = () => { 5 | console.log('app.js > someFunction'); 6 | }; 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/images/rPI-400x400.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server-scripts/src/images/rPI-400x400.jpg -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/vendors~main-bundle.js.br: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/vendors~main-bundle.js.br -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/vendors~main-bundle.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpersonalwebsite/react/HEAD/examples/react-redux-webpack-client-server/public/vendors~main-bundle.js.gz -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/server/test.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const config = require('../config/webpack.config.prod.server.js'); 3 | webpack(config); 4 | 5 | console.log(1); 6 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/tempPolyfills.js: -------------------------------------------------------------------------------- 1 | const requestAnimationFrame = (global.requestAnimationFrame = callback => { 2 | setTimeout(callback, 0); 3 | }); 4 | export default requestAnimationFrame; 5 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | ReactDOM.render(, document.getElementById('root')); 6 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/server/test.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const config = require('../config/webpack.config.prod.server.js'); 3 | webpack(config); 4 | 5 | console.log(1); 6 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/tempPolyfills.js: -------------------------------------------------------------------------------- 1 | const requestAnimationFrame = (global.requestAnimationFrame = callback => { 2 | setTimeout(callback, 0); 3 | }); 4 | export default requestAnimationFrame; 5 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/tempPolyfills.js: -------------------------------------------------------------------------------- 1 | const requestAnimationFrame = (global.requestAnimationFrame = callback => { 2 | setTimeout(callback, 0); 3 | }); 4 | export default requestAnimationFrame; 5 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/jest/tempPolyfills.js: -------------------------------------------------------------------------------- 1 | const requestAnimationFrame = (global.requestAnimationFrame = callback => { 2 | setTimeout(callback, 0); 3 | }); 4 | export default requestAnimationFrame; 5 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/jest/tempPolyfills.js: -------------------------------------------------------------------------------- 1 | const requestAnimationFrame = (global.requestAnimationFrame = callback => { 2 | setTimeout(callback, 0); 3 | }); 4 | export default requestAnimationFrame; 5 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/server/index.js: -------------------------------------------------------------------------------- 1 | require('@babel/register')({ 2 | presets: ['@babel/preset-env', '@babel/preset-react'] 3 | }); 4 | 5 | //module.exports = require('./server.js'); 6 | require('./server.js'); 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/server/index.js: -------------------------------------------------------------------------------- 1 | require('@babel/register')({ 2 | presets: ['@babel/preset-env', '@babel/preset-react'] 3 | }); 4 | 5 | //module.exports = require('./server.js'); 6 | require('./server.js'); 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react"], 3 | "plugins": [ 4 | "@babel/plugin-proposal-class-properties", 5 | ["emotion", { "sourceMap": true, "autoLabel": true }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/Intro.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | const Intro = () => { 4 | return ( 5 |
6 |

Hello

7 | Intro 8 |
9 | ); 10 | }; 11 | 12 | export default Intro; 13 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # misc 5 | .DS_Store 6 | .env.local 7 | .env.development.local 8 | .env.test.local 9 | .env.production.local 10 | 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # misc 5 | .DS_Store 6 | .env.local 7 | .env.development.local 8 | .env.test.local 9 | .env.production.local 10 | 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react"], 3 | "plugins": [ 4 | "@babel/plugin-proposal-class-properties", 5 | ["emotion", { "sourceMap": true, "autoLabel": true }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/Intro.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | const Intro = () => { 4 | return ( 5 |
6 |

Hello!

7 | Intro 8 |
9 | ); 10 | }; 11 | 12 | export default Intro; 13 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | import commentsReducer from './commentsReducer'; 3 | const rootReducer = combineReducers({ 4 | comments: commentsReducer 5 | }); 6 | 7 | export default rootReducer; 8 | -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # misc 5 | .DS_Store 6 | .env.local 7 | .env.development.local 8 | .env.test.local 9 | .env.production.local 10 | 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/App.css.js: -------------------------------------------------------------------------------- 1 | const settings = { 2 | color: 'white' 3 | }; 4 | 5 | const sectionTitle = { 6 | color: settings.color, 7 | backgroundColor: 'grey', 8 | padding: '20px' 9 | }; 10 | 11 | export default { sectionTitle }; 12 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | import commentsReducer from './commentsReducer'; 3 | const rootReducer = combineReducers({ 4 | comments: commentsReducer 5 | }); 6 | 7 | export default rootReducer; 8 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/config/webpack.config.dev.js: -------------------------------------------------------------------------------- 1 | const merge = require('webpack-merge'); 2 | const commonConfig = require('./webpack.config.js'); 3 | 4 | const config = { 5 | mode: 'development' 6 | }; 7 | 8 | module.exports = merge(commonConfig, config); 9 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # misc 5 | .DS_Store 6 | .env.local 7 | .env.development.local 8 | .env.test.local 9 | .env.production.local 10 | 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/Intro.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | const Intro = () => { 4 | return ( 5 |
6 |

Hello!

7 | Intro 8 |
9 | ); 10 | }; 11 | 12 | export default Intro; 13 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/setupTests.js: -------------------------------------------------------------------------------- 1 | import requestAnimationFrame from './tempPolyfills'; 2 | 3 | import { configure } from 'enzyme'; 4 | 5 | import Adapter from 'enzyme-adapter-react-16'; 6 | configure({ adapter: new Adapter(), disableLifecycleMethods: true }); 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/App.css.js: -------------------------------------------------------------------------------- 1 | const settings = { 2 | color: 'white' 3 | }; 4 | 5 | const sectionTitle = { 6 | color: settings.color, 7 | backgroundColor: 'grey', 8 | padding: '20px' 9 | }; 10 | 11 | export default { sectionTitle }; 12 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | import commentsReducer from './commentsReducer'; 3 | const rootReducer = combineReducers({ 4 | comments: commentsReducer 5 | }); 6 | 7 | export default rootReducer; 8 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/server/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # misc 5 | .DS_Store 6 | .env.local 7 | .env.development.local 8 | .env.test.local 9 | .env.production.local 10 | 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/setupTests.js: -------------------------------------------------------------------------------- 1 | import requestAnimationFrame from './tempPolyfills'; 2 | 3 | import { configure } from 'enzyme'; 4 | 5 | import Adapter from 'enzyme-adapter-react-16'; 6 | configure({ adapter: new Adapter(), disableLifecycleMethods: true }); 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/server/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # misc 5 | .DS_Store 6 | .env.local 7 | .env.development.local 8 | .env.test.local 9 | .env.production.local 10 | 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/setupTests.js: -------------------------------------------------------------------------------- 1 | import requestAnimationFrame from './tempPolyfills'; 2 | 3 | import { configure } from 'enzyme'; 4 | 5 | import Adapter from 'enzyme-adapter-react-16'; 6 | configure({ adapter: new Adapter(), disableLifecycleMethods: true }); 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/jest/setupTests.js: -------------------------------------------------------------------------------- 1 | import requestAnimationFrame from './tempPolyfills'; 2 | 3 | import { configure } from 'enzyme'; 4 | 5 | import Adapter from 'enzyme-adapter-react-16'; 6 | configure({ adapter: new Adapter(), disableLifecycleMethods: true }); 7 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/jest/setupTests.js: -------------------------------------------------------------------------------- 1 | import requestAnimationFrame from './tempPolyfills'; 2 | 3 | import { configure } from 'enzyme'; 4 | 5 | import Adapter from 'enzyme-adapter-react-16'; 6 | configure({ adapter: new Adapter(), disableLifecycleMethods: true }); 7 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: { 5 | main: './src/index.js' 6 | }, 7 | mode: 'production', 8 | output: { 9 | filename: 'bundle.js', 10 | path: path.resolve(__dirname, 'dist') 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render( < App / > , div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); -------------------------------------------------------------------------------- /examples/basic-react-example-state/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render( < App / > , div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render( < App / > , div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render( < App / > , div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render( < App / > , div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render( < App / > , div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/TestingSSR.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class TestingSSR extends Component { 4 | state = { 5 | label: 'SSR' 6 | }; 7 | 8 | render() { 9 | return ( 10 |
11 |
{`Testing ${this.state.label}`}
12 |
13 | ); 14 | } 15 | } 16 | 17 | export default TestingSSR; 18 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/TestingSSR.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class TestingSSR extends Component { 4 | state = { 5 | label: 'SSR' 6 | }; 7 | 8 | render() { 9 | return ( 10 |
11 |
{`Testing ${this.state.label}`}
12 |
13 | ); 14 | } 15 | } 16 | 17 | export default TestingSSR; 18 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "body-parser": "^1.18.3", 13 | "express": "^4.16.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "body-parser": "^1.18.3", 13 | "express": "^4.16.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "build": "webpack --config=webpack.config.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "webpack": "^4.23.1", 14 | "webpack-cli": "^3.1.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/jest/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "collectCoverageFrom": [ 4 | "/src/**/*.{js,jsx,mjs}", 5 | "!**/node_modules/**" 6 | ], 7 | "moduleNameMapper": { 8 | "\\.css$": "identity-obj-proxy" 9 | }, 10 | "transform": { 11 | "^.+\\.(js|jsx|mjs)$": "/node_modules/babel-jest" 12 | }, 13 | "setupFiles": ["/config/jest/setupTests.js"] 14 | } 15 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React + Redux + redux-thunk", 3 | "name": "React + Redux + redux-thunk", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React + Redux + redux-thunk", 3 | "name": "React + Redux + redux-thunk", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React + Redux + redux-thunk", 3 | "name": "React + Redux + redux-thunk", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React + Redux + redux-thunk", 3 | "name": "React + Redux + redux-thunk", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/jest/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "collectCoverageFrom": [ 4 | "/src/**/*.{js,jsx,mjs}", 5 | "!**/node_modules/**" 6 | ], 7 | "moduleNameMapper": { 8 | "\\.css$": "identity-obj-proxy" 9 | }, 10 | "transform": { 11 | "^.+\\.(js|jsx|mjs)$": "/node_modules/babel-jest" 12 | }, 13 | "setupFiles": ["/config/jest/setupTests.js"] 14 | } 15 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React + Redux + redux-thunk", 3 | "name": "React + Redux + redux-thunk", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/src/FunctionalComponent.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | 3 | const FunctionalComponent = props => { 4 | const [nameState, setNameState] = useState('J'); 5 | return 6 | Hello {nameState} 7 | setNameState(event.target.value)} /> 9 | 10 | } 11 | 12 | export default FunctionalComponent; -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React + Redux + redux-thunk", 3 | "name": "React + Redux + redux-thunk", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/webpack.config.dev.client.js: -------------------------------------------------------------------------------- 1 | //const webpack = require('webpack'); 2 | const merge = require('webpack-merge'); 3 | const commonConfig = require('./webpack.config.js'); 4 | 5 | const config = { 6 | mode: 'development', 7 | entry: { 8 | main: ['./src/index.js'] 9 | }, 10 | devServer: { 11 | contentBase: '/..public', 12 | overlay: true 13 | } 14 | }; 15 | 16 | module.exports = merge(commonConfig, config); 17 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/reducers/commentsReducer.js: -------------------------------------------------------------------------------- 1 | import { FETCH_COMMENTS } from '../actions/types'; 2 | 3 | export default (state = [], action) => { 4 | switch (action.type) { 5 | case FETCH_COMMENTS: 6 | const commentsPayload = 7 | action.payload.length > 10 8 | ? action.payload.slice(0, 10) 9 | : action.payload; 10 | return [...state, ...commentsPayload]; 11 | 12 | default: 13 | return state; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/reducers/commentsReducer.js: -------------------------------------------------------------------------------- 1 | import { FETCH_COMMENTS } from '../actions/types'; 2 | 3 | export default (state = [], action) => { 4 | switch (action.type) { 5 | case FETCH_COMMENTS: 6 | const commentsPayload = 7 | action.payload.length > 10 8 | ? action.payload.slice(0, 10) 9 | : action.payload; 10 | return [...state, ...commentsPayload]; 11 | 12 | default: 13 | return state; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/reducers/commentsReducer.js: -------------------------------------------------------------------------------- 1 | import { FETCH_COMMENTS } from '../actions/types'; 2 | 3 | export default (state = [], action) => { 4 | switch (action.type) { 5 | case FETCH_COMMENTS: 6 | const commentsPayload = 7 | action.payload.length > 10 8 | ? action.payload.slice(0, 10) 9 | : action.payload; 10 | return [...state, ...commentsPayload]; 11 | 12 | default: 13 | return state; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import ClassComponent from './ClassComponent'; 3 | import FunctionalComponent from './FunctionalComponent'; 4 | 5 | 6 | class App extends Component { 7 | render() { 8 | return ( 9 | 10 |

Functional Component: useState

11 | 12 | 13 |
14 | 15 |

Class based Component: state

16 | 17 |
18 | ) 19 | } 20 | } 21 | 22 | export default App; -------------------------------------------------------------------------------- /notesToPlace.md: -------------------------------------------------------------------------------- 1 | **Coercion** 2 | 3 | Is when we force one data type into another. This is because JS is pretty flexible handling data types. 4 | 5 | Example: 6 | 7 | ```javascript 8 | console.log(1 + true); 9 | console.log('1' + 1); 10 | ``` 11 | 12 | We force or coerce true into 1 and 1 int/number into 1 string 13 | 14 | The following operators convert data types values into `numbers`: `- * / %` 15 | However, `+` as we saw, converts by default into a `string`. 16 | 17 | ```javascript 18 | console.log('1' + 1); 19 | console.log('1' - 1); 20 | ``` 21 | 22 | Result: 23 | 11 24 | 0 25 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/src/ClassComponent.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class ClassComponent extends Component { 4 | state = { 5 | name: 'J' 6 | } 7 | render() { 8 | const { name } = this.state; 9 | return ( 10 | 11 | Hello {name} 12 | this.setState({ name: event.target.value })} /> 14 | 15 | ); 16 | } 17 | } 18 | 19 | export default ClassComponent; -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/webpack.config.prod.server.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const merge = require('webpack-merge'); 3 | const commonConfig = require('./webpack.config.js'); 4 | var nodeExternals = require('webpack-node-externals'); 5 | 6 | const config = { 7 | mode: 'production', 8 | target: 'node', 9 | externals: nodeExternals(), 10 | entry: './server/index.js', 11 | output: { 12 | path: path.resolve(__dirname, '../build'), 13 | filename: './server-prod-bundle.js' 14 | } 15 | }; 16 | 17 | module.exports = merge(commonConfig, config); 18 | -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BasicReactMapWithState", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.8.6", 7 | "react-dom": "^16.8.6", 8 | "react-scripts": "3.0.1" 9 | }, 10 | "scripts": { 11 | "start": "react-scripts start", 12 | "build": "react-scripts build", 13 | "test": "react-scripts test --env=jsdom --watchAll", 14 | "eject": "react-scripts eject" 15 | }, 16 | "browserslist": [ 17 | ">0.2%", 18 | "not dead", 19 | "not ie <= 11", 20 | "not op_mini all" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # misc 12 | .DS_Store 13 | .env 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | #npm cache dir 20 | .npm 21 | 22 | # production 23 | /build 24 | 25 | # Runtime data 26 | pids 27 | *.pid 28 | *.seed 29 | *.pid.lock 30 | 31 | # testing 32 | /coverage 33 | **/__snapshots__ 34 | 35 | # TS v1 declarations files 36 | typings/ 37 | 38 | # Yarn Integrity file 39 | .yarn-integrity 40 | 41 | *stats.* 42 | 43 | *-old* 44 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/webpack.config.dev.server.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const merge = require('webpack-merge'); 3 | const commonConfig = require('./webpack.config.js'); 4 | var nodeExternals = require('webpack-node-externals'); 5 | 6 | const config = { 7 | name: 'server', 8 | mode: 'development', 9 | target: 'node', 10 | externals: nodeExternals(), 11 | entry: './server/index.js', 12 | output: { 13 | path: path.resolve(__dirname, '../public'), 14 | filename: 'server-dev-bundle.js' 15 | } 16 | }; 17 | 18 | module.exports = merge(commonConfig, config); 19 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/webpack.config.prod.server.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const merge = require('webpack-merge'); 3 | const commonConfig = require('./webpack.config.js'); 4 | var nodeExternals = require('webpack-node-externals'); 5 | 6 | const config = { 7 | name: 'server', 8 | mode: 'production', 9 | target: 'node', 10 | externals: nodeExternals(), 11 | entry: './server/index.js', 12 | output: { 13 | path: path.resolve(__dirname, '../build'), 14 | filename: 'server-prod-bundle.js' 15 | } 16 | }; 17 | 18 | module.exports = merge(commonConfig, config); 19 | -------------------------------------------------------------------------------- /examples/basic-react-example-state/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BasicReactMapWithState", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.8.6", 7 | "react-dom": "^16.8.6", 8 | "react-scripts": "3.0.1", 9 | "uuid": "^3.3.2" 10 | }, 11 | "scripts": { 12 | "start": "react-scripts start", 13 | "build": "react-scripts build", 14 | "test": "react-scripts test --env=jsdom --watchAll", 15 | "eject": "react-scripts eject" 16 | }, 17 | "browserslist": [ 18 | ">0.2%", 19 | "not dead", 20 | "not ie <= 11", 21 | "not op_mini all" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # misc 12 | .DS_Store 13 | .env 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | #npm cache dir 20 | .npm 21 | 22 | # production 23 | /build 24 | 25 | # Runtime data 26 | pids 27 | *.pid 28 | *.seed 29 | *.pid.lock 30 | 31 | # testing 32 | /coverage 33 | **/__snapshots__ 34 | 35 | # TS v1 declarations files 36 | typings/ 37 | 38 | # Yarn Integrity file 39 | .yarn-integrity 40 | 41 | *stats.* 42 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BasicReactMapWithKey", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.7.0", 7 | "react-dom": "^16.7.0", 8 | "react-scripts": "3.0.1", 9 | "uuid": "^3.3.2" 10 | }, 11 | "scripts": { 12 | "start": "react-scripts start", 13 | "build": "react-scripts build", 14 | "test": "react-scripts test --env=jsdom --watchAll", 15 | "eject": "react-scripts eject" 16 | }, 17 | "browserslist": [ 18 | ">0.2%", 19 | "not dead", 20 | "not ie <= 11", 21 | "not op_mini all" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # misc 12 | .DS_Store 13 | .env 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | #npm cache dir 20 | .npm 21 | 22 | # production 23 | /build 24 | 25 | # Runtime data 26 | pids 27 | *.pid 28 | *.seed 29 | *.pid.lock 30 | 31 | # testing 32 | /coverage 33 | **/__snapshots__ 34 | 35 | # TS v1 declarations files 36 | typings/ 37 | 38 | # Yarn Integrity file 39 | .yarn-integrity 40 | 41 | *stats.* 42 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # misc 12 | .DS_Store 13 | .env 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | #npm cache dir 20 | .npm 21 | 22 | # production 23 | /build 24 | 25 | # Runtime data 26 | pids 27 | *.pid 28 | *.seed 29 | *.pid.lock 30 | 31 | # testing 32 | /coverage 33 | **/__snapshots__ 34 | 35 | # TS v1 declarations files 36 | typings/ 37 | 38 | # Yarn Integrity file 39 | .yarn-integrity 40 | 41 | *stats.* 42 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/config/webpack.config.prod.js: -------------------------------------------------------------------------------- 1 | const merge = require('webpack-merge'); 2 | const baseConfig = require('./webpack.config.js'); 3 | 4 | const path = require('path'); 5 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 6 | 7 | let pathsToClean = ['dist/', 'build/', 'public/']; 8 | 9 | let cleanOptions = { 10 | root: path.resolve(__dirname, '../'), 11 | exclude: ['template.html', 'manifest.json', 'favicon.ico'], 12 | verbose: true, 13 | dry: false 14 | }; 15 | 16 | const config = { 17 | stats: { 18 | colors: true 19 | }, 20 | mode: 'production', 21 | plugins: [new CleanWebpackPlugin(pathsToClean, cleanOptions)] 22 | }; 23 | 24 | module.exports = merge(baseConfig, config); 25 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/actions/index.js: -------------------------------------------------------------------------------- 1 | import { FETCH_COMMENTS } from './types'; 2 | 3 | import axios from 'axios'; 4 | 5 | const api = 'https://jsonplaceholder.typicode.com/'; 6 | 7 | const headers = { 8 | Accept: 'application/json' 9 | }; 10 | 11 | //export function fetchComments() { 12 | export const fetchComments = () => dispatch => { 13 | const query = 'comments'; 14 | const endPoint = `${api}${query}`; 15 | 16 | /* 17 | const request = axios.get(endPoint, { headers }); 18 | return { 19 | type: FETCH_COMMENTS, 20 | payload: request 21 | }; 22 | */ 23 | return axios.get(endPoint, { headers }).then(response => { 24 | dispatch({ type: FETCH_COMMENTS, payload: response.data }); 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/actions/index.js: -------------------------------------------------------------------------------- 1 | import { FETCH_COMMENTS } from './types'; 2 | 3 | import axios from 'axios'; 4 | 5 | const api = 'https://jsonplaceholder.typicode.com/'; 6 | 7 | const headers = { 8 | Accept: 'application/json' 9 | }; 10 | 11 | //export function fetchComments() { 12 | export const fetchComments = () => dispatch => { 13 | const query = 'comments'; 14 | const endPoint = `${api}${query}`; 15 | 16 | /* 17 | const request = axios.get(endPoint, { headers }); 18 | return { 19 | type: FETCH_COMMENTS, 20 | payload: request 21 | }; 22 | */ 23 | return axios.get(endPoint, { headers }).then(response => { 24 | dispatch({ type: FETCH_COMMENTS, payload: response.data }); 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/actions/index.js: -------------------------------------------------------------------------------- 1 | import { FETCH_COMMENTS } from './types'; 2 | 3 | import axios from 'axios'; 4 | 5 | const api = 'https://jsonplaceholder.typicode.com/'; 6 | 7 | const headers = { 8 | Accept: 'application/json' 9 | }; 10 | 11 | //export function fetchComments() { 12 | export const fetchComments = () => dispatch => { 13 | const query = 'comments'; 14 | const endPoint = `${api}${query}`; 15 | 16 | /* 17 | const request = axios.get(endPoint, { headers }); 18 | return { 19 | type: FETCH_COMMENTS, 20 | payload: request 21 | }; 22 | */ 23 | return axios.get(endPoint, { headers }).then(response => { 24 | dispatch({ type: FETCH_COMMENTS, payload: response.data }); 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/Intro.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | import React from 'react'; 3 | import ReactDOM from 'react-dom'; 4 | import Intro from './Intro'; 5 | 6 | it('renders without crashing', () => { 7 | const div = document.createElement('div'); 8 | ReactDOM.render(, div); 9 | }); 10 | */ 11 | 12 | import React from 'react'; 13 | import ReactDOM from 'react-dom'; 14 | import { mount } from 'enzyme'; 15 | import Intro from './Intro'; 16 | 17 | describe('', () => { 18 | const wrapper = mount(); 19 | 20 | it('matches the previous Snapshot', () => { 21 | expect(wrapper).toMatchSnapshot(); 22 | }); 23 | it('has a h1 as title with class title', () => { 24 | expect(wrapper.find('h1').exists()).toBe(true); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/Intro.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | import React from 'react'; 3 | import ReactDOM from 'react-dom'; 4 | import Intro from './Intro'; 5 | 6 | it('renders without crashing', () => { 7 | const div = document.createElement('div'); 8 | ReactDOM.render(, div); 9 | }); 10 | */ 11 | 12 | import React from 'react'; 13 | import ReactDOM from 'react-dom'; 14 | import { shallow } from 'enzyme'; 15 | import Intro from './Intro'; 16 | 17 | describe('', () => { 18 | const wrapper = shallow(); 19 | 20 | it('matches the previous Snapshot', () => { 21 | expect(wrapper).toMatchSnapshot(); 22 | }); 23 | it('has a h1 as title with class title', () => { 24 | expect(wrapper.find('h1').exists()).toBe(true); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/Intro.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | import React from 'react'; 3 | import ReactDOM from 'react-dom'; 4 | import Intro from './Intro'; 5 | 6 | it('renders without crashing', () => { 7 | const div = document.createElement('div'); 8 | ReactDOM.render(, div); 9 | }); 10 | */ 11 | 12 | import React from 'react'; 13 | import ReactDOM from 'react-dom'; 14 | import { shallow } from 'enzyme'; 15 | import Intro from './Intro'; 16 | 17 | describe('', () => { 18 | const wrapper = shallow(); 19 | 20 | it('matches the previous Snapshot', () => { 21 | expect(wrapper).toMatchSnapshot(); 22 | }); 23 | it('has a h1 as title with class title', () => { 24 | expect(wrapper.find('h1').exists()).toBe(true); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/webpack.config.dev.server.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const merge = require('webpack-merge'); 3 | const commonConfig = require('./webpack.config.js'); 4 | 5 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') 6 | .BundleAnalyzerPlugin; 7 | 8 | const config = { 9 | mode: 'development', 10 | entry: { 11 | main: ['webpack-hot-middleware/client?reload=true', './src/index.js'] 12 | }, 13 | devServer: { 14 | contentBase: '/..public', 15 | hot: true, 16 | overlay: true 17 | }, 18 | plugins: [ 19 | new webpack.HotModuleReplacementPlugin(), 20 | new BundleAnalyzerPlugin({ 21 | generateStatsFile: true 22 | }) 23 | ] 24 | }; 25 | 26 | module.exports = merge(commonConfig, config); 27 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | 4 | import { fetchComments } from './actions'; 5 | 6 | class App extends Component { 7 | componentDidMount() { 8 | this.props.fetchComments(); 9 | } 10 | 11 | renderComments = () => { 12 | return this.props.comments.map(comment => { 13 | return
  • {comment.name}
  • ; 14 | }); 15 | }; 16 | 17 | render() { 18 | return ( 19 |
    20 |

    List of comments 101

    21 |
    {this.renderComments()}
    22 |
    23 | ); 24 | } 25 | } 26 | 27 | const mapStateToProps = ({ comments }) => { 28 | return { 29 | comments 30 | }; 31 | }; 32 | 33 | export default connect(mapStateToProps, { fetchComments })(App); 34 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/server/BasicController.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const isHtmlWebpackPlugin = process.env.WEBPACK_STATIC_HTML_BUILD; 3 | 4 | const React = require('react'); 5 | const renderToString = require('react-dom/server').renderToString; 6 | const TestingSSR = require('../src/TestingSSR').default; 7 | 8 | class BasicController { 9 | constructor(app) { 10 | this.app = app; 11 | this.allRoutes(); 12 | } 13 | 14 | allRoutes() { 15 | if (isHtmlWebpackPlugin != 'true') { 16 | this.app.get('*', (req, res) => { 17 | res.send(` 18 | 19 | 20 |
    ${renderToString()}
    21 | 22 | 23 | `); 24 | }); 25 | } 26 | } 27 | } 28 | 29 | module.exports = app => { 30 | return new BasicController(app); 31 | }; 32 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/server/BasicController.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const isHtmlWebpackPlugin = process.env.WEBPACK_STATIC_HTML_BUILD; 3 | 4 | const React = require('react'); 5 | const renderToString = require('react-dom/server').renderToString; 6 | const TestingSSR = require('../src/TestingSSR').default; 7 | 8 | class BasicController { 9 | constructor(app) { 10 | this.app = app; 11 | this.allRoutes(); 12 | } 13 | 14 | allRoutes() { 15 | if (isHtmlWebpackPlugin != 'true') { 16 | this.app.get('*', (req, res) => { 17 | res.send(` 18 | 19 | 20 |
    ${renderToString()}
    21 | 22 | 23 | `); 24 | }); 25 | } 26 | } 27 | } 28 | 29 | module.exports = app => { 30 | return new BasicController(app); 31 | }; 32 | -------------------------------------------------------------------------------- /greenkeeper.json: -------------------------------------------------------------------------------- 1 | { 2 | "groups": { 3 | "default": { 4 | "packages": [ 5 | "examples/basic-react-example-lifecycle/package.json", 6 | "examples/basic-react-example-state/package.json", 7 | "examples/basic-react-example[map-with-key]/package.json", 8 | "examples/basic-redux-example[redux-promise]/package.json", 9 | "examples/basic-redux-example[redux-thunk]/package.json", 10 | "examples/basic-webpack[default]/package.json", 11 | "examples/react-redux-webpack-client-server-scripts/package.json", 12 | "examples/react-redux-webpack-client-server-scripts/server/package.json", 13 | "examples/react-redux-webpack-client-server/package.json", 14 | "examples/react-redux-webpack-client-server/server/package.json", 15 | "examples/react-redux-webpack-client/package.json" 16 | ] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/index.js: -------------------------------------------------------------------------------- 1 | //require('babel-runtime/regenerator'); 2 | //require('webpack-hot-middleware/client?reload=true'); 3 | import React from 'react'; 4 | import { BrowserRouter, Route } from 'react-router-dom'; 5 | import ReactDOM from 'react-dom'; 6 | import rootReducer from './reducers'; 7 | import { Provider } from 'react-redux'; 8 | import { createStore, applyMiddleware, compose } from 'redux'; 9 | 10 | import '@babel/polyfill'; 11 | 12 | import reduxThunk from 'redux-thunk'; 13 | import App from './App'; 14 | 15 | import './index.css'; 16 | 17 | const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 18 | 19 | const store = createStore(rootReducer, applyMiddleware(reduxThunk)); 20 | 21 | ReactDOM.render( 22 | 23 | 24 |
    25 | 26 |
    27 |
    28 |
    , 29 | document.getElementById('root') 30 | ); 31 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/config/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HTMLWebpackPlugin = require('html-webpack-plugin'); 3 | 4 | module.exports = { 5 | // entry: './src/index.js', 6 | /* 7 | stats: { 8 | colors: true 9 | }, 10 | */ 11 | entry: { 12 | main: './src/index.js', 13 | other: './src/other.js' 14 | }, 15 | //mode: 'development', 16 | output: { 17 | path: path.resolve(__dirname, '../public'), 18 | //publicPath: '/', 19 | filename: './[name]bundle.js' 20 | }, 21 | module: { 22 | rules: [ 23 | { 24 | test: /\.js$/, 25 | exclude: /node_modules/, 26 | use: [ 27 | { 28 | loader: 'babel-loader' 29 | } 30 | ] 31 | } 32 | ] 33 | }, 34 | devServer: { 35 | contentBase: 'public' 36 | }, 37 | plugins: [ 38 | new HTMLWebpackPlugin({ 39 | template: './public/template.html' 40 | }) 41 | ] 42 | }; 43 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/index.js: -------------------------------------------------------------------------------- 1 | //require('babel-runtime/regenerator'); 2 | //require('webpack-hot-middleware/client?reload=true'); 3 | import React from 'react'; 4 | import { BrowserRouter, Route } from 'react-router-dom'; 5 | import ReactDOM from 'react-dom'; 6 | import rootReducer from './reducers'; 7 | import { Provider } from 'react-redux'; 8 | import { createStore, applyMiddleware, compose } from 'redux'; 9 | 10 | import '@babel/polyfill'; 11 | 12 | import reduxThunk from 'redux-thunk'; 13 | import App from './App'; 14 | 15 | import './index.css'; 16 | 17 | const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 18 | 19 | const store = createStore(rootReducer, applyMiddleware(reduxThunk)); 20 | 21 | ReactDOM.render( 22 | 23 | 24 |
    25 | 26 |
    27 |
    28 |
    , 29 | document.getElementById('root') 30 | ); 31 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/public/otherbundle.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=47)}({47:function(e,t){console.log("I´m the other entry!")}}); -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import Child from './Child'; 3 | 4 | class App extends Component { 5 | 6 | constructor(props) { 7 | super(props); 8 | console.log('App > constructor()') 9 | } 10 | 11 | state = { 12 | name: 'Peter' 13 | } 14 | 15 | static getDerivedStateFromProps(props, state) { 16 | console.log('App > getDerivedStateFromProps()', props); 17 | return state; 18 | } 19 | 20 | componentWillMount() { 21 | console.log('App > componentWillMount()'); 22 | } 23 | 24 | componentDidMount() { 25 | console.log('App > componentDidMount()'); 26 | } 27 | 28 | render() { 29 | 30 | const { name } = this.state; 31 | 32 | console.log('App > render()'); 33 | 34 | return ( 35 | 36 |
    37 | Hi! 38 | 39 |
    40 | 41 |
    42 | ) 43 | } 44 | } 45 | 46 | export default App; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 React 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/src/Child.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | 3 | class Child extends Component { 4 | 5 | componentWillReceiveProps(props) { 6 | console.log('Child > componentWillReceiveProps()'); 7 | } 8 | 9 | shouldComponentUpdate(nextProps, nextState) { 10 | console.log('Child > shouldComponentUpdate()'); 11 | return true; 12 | } 13 | 14 | getSnapshotBeforeUpdate(prevProps, prevState) { 15 | console.log('Child > getSnapshotBeforeUpdate()') 16 | return { friend: 'Peter' } 17 | } 18 | 19 | componentWillUpdate() { 20 | console.log('Child > componentWillUpdate()') 21 | } 22 | 23 | componentDidUpdate(prevProps, prevState, snapshot) { 24 | console.log('Child > componentDidUpdate()') 25 | console.log(snapshot) 26 | } 27 | 28 | render() { 29 | 30 | const { name } = this.props; 31 | 32 | console.log('Child > render()') 33 | return ( 34 | I'm a Child! And my name is {name} 35 | ); 36 | } 37 | 38 | } 39 | 40 | export default Child; -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | 4 | import { fetchComments } from './actions'; 5 | //import { css, jsx } from '@emotion/core'; 6 | import styled from '@emotion/styled'; 7 | 8 | import styles from './App.css'; 9 | import cssInJs from './App.css.js'; 10 | 11 | import rPI from './images/rPI-400x400.jpg'; 12 | 13 | const CommentsBox = styled('div')` 14 | background-color: lavender; 15 | `; 16 | 17 | /* 18 | const listItem = css` 19 | list-style: none; 20 | padding: 0; 21 | `; 22 | 23 | const bold = css` 24 | font-weight: 'bold'; 25 | `; 26 | */ 27 | 28 | class App extends Component { 29 | componentDidMount() { 30 | this.props.fetchComments(); 31 | } 32 | 33 | renderComments = () => { 34 | return this.props.comments.map(comment => { 35 | return
  • {comment.name}
  • ; 36 | }); 37 | }; 38 | 39 | render() { 40 | return ( 41 |
    42 |

    List of comments 101

    43 | {this.renderComments()} 44 | Rasp. Pi Logo 45 |
    46 | ); 47 | } 48 | } 49 | 50 | const mapStateToProps = ({ comments }) => { 51 | return { 52 | comments 53 | }; 54 | }; 55 | 56 | export default connect(mapStateToProps, { fetchComments })(App); 57 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | 4 | import { fetchComments } from './actions'; 5 | //import { css, jsx } from '@emotion/core'; 6 | import styled from '@emotion/styled'; 7 | 8 | import styles from './App.css'; 9 | import cssInJs from './App.css.js'; 10 | 11 | import rPI from './images/rPI-400x400.jpg'; 12 | 13 | const CommentsBox = styled('div')` 14 | background-color: lavender; 15 | `; 16 | 17 | /* 18 | const listItem = css` 19 | list-style: none; 20 | padding: 0; 21 | `; 22 | 23 | const bold = css` 24 | font-weight: 'bold'; 25 | `; 26 | */ 27 | 28 | class App extends Component { 29 | componentDidMount() { 30 | this.props.fetchComments(); 31 | } 32 | 33 | renderComments = () => { 34 | return this.props.comments.map(comment => { 35 | return
  • {comment.name}
  • ; 36 | }); 37 | }; 38 | 39 | render() { 40 | return ( 41 |
    42 |

    List of comments 101

    43 | {this.renderComments()} 44 | Rasp. Pi Logo 45 |
    46 | ); 47 | } 48 | } 49 | 50 | const mapStateToProps = ({ comments }) => { 51 | return { 52 | comments 53 | }; 54 | }; 55 | 56 | export default connect(mapStateToProps, { fetchComments })(App); 57 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/webpack.config.dev.client.js: -------------------------------------------------------------------------------- 1 | /* 2 | //const webpack = require('webpack'); 3 | const merge = require('webpack-merge'); 4 | const commonConfig = require('./webpack.config.js'); 5 | 6 | const config = { 7 | mode: 'development', 8 | entry: { 9 | main: './src/index.js' 10 | }, 11 | devServer: { 12 | contentBase: '/..public', 13 | overlay: true 14 | } 15 | }; 16 | 17 | module.exports = merge(commonConfig, config); 18 | */ 19 | const path = require('path'); 20 | const webpack = require('webpack'); 21 | const merge = require('webpack-merge'); 22 | const commonConfig = require('./webpack.config.js'); 23 | 24 | /* 25 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') 26 | .BundleAnalyzerPlugin; 27 | */ 28 | 29 | const config = { 30 | name: 'client', 31 | target: 'web', 32 | mode: 'development', 33 | entry: { 34 | main: ['webpack-hot-middleware/client?reload=true', './src/index.js'], 35 | other: './src/other.js' 36 | }, 37 | output: { 38 | path: path.resolve(__dirname, '../public'), 39 | //publicPath: '/', 40 | filename: './[name]-bundle.js' 41 | }, 42 | devServer: { 43 | contentBase: '/..public', 44 | hot: true, 45 | overlay: true 46 | }, 47 | plugins: [ 48 | new webpack.HotModuleReplacementPlugin() 49 | /*, 50 | new BundleAnalyzerPlugin({ 51 | generateStatsFile: true 52 | }) 53 | */ 54 | ] 55 | }; 56 | 57 | module.exports = merge(commonConfig, config); 58 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/webpack.config.prod.js: -------------------------------------------------------------------------------- 1 | const merge = require('webpack-merge'); 2 | const baseConfig = require('./webpack.config.js'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); 5 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 6 | 7 | const path = require('path'); 8 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 9 | 10 | const BrotliPlugin = require('brotli-webpack-plugin'); 11 | const CompressionPlugin = require('compression-webpack-plugin'); 12 | 13 | let pathsToClean = ['dist/', 'build/', 'public/']; 14 | 15 | let cleanOptions = { 16 | root: path.resolve(__dirname, '../'), 17 | exclude: ['template.html', 'manifest.json', 'favicon.ico'], 18 | verbose: true, 19 | dry: false 20 | }; 21 | 22 | const config = { 23 | mode: 'production', 24 | optimization: { 25 | minimizer: [new UglifyJsPlugin()] 26 | }, 27 | plugins: [ 28 | new CleanWebpackPlugin(pathsToClean, cleanOptions), 29 | new MiniCssExtractPlugin({ 30 | filename: '[name]-[contenthash].css' 31 | }), 32 | new OptimizeCssAssetsPlugin({ 33 | assetNameRegExp: /\.css$/g, 34 | cssProcessor: require('cssnano'), 35 | cssProcessorOptions: { discardComments: { removeAll: true } }, 36 | canPrint: true 37 | }), 38 | new CompressionPlugin({ 39 | algorithm: 'gzip' 40 | }), 41 | new BrotliPlugin() 42 | ] 43 | }; 44 | 45 | module.exports = merge(baseConfig, config); 46 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import uuid from 'uuid'; 3 | 4 | const Child = props => ( 5 |
    6 |
    7 | I´m receiving...{' '} 8 | {props.onShowingHello.map(({ salutation, timestamp }, index) => ( 9 |
  • 10 | 16 | 17 |
  • 18 | ))} 19 |
    20 |
    21 | ); 22 | 23 | class App extends Component { 24 | state = { 25 | ourSalutation: [ 26 | { salutation: 'Hi', timestamp: '29519bf2-c68e-11e8-8f1c-f3e5f253a17f' }, 27 | { 28 | salutation: 'Hello', 29 | timestamp: '3c72eae1-c68e-11e8-a508-89da3bf216bc' 30 | }, 31 | { salutation: 'Hola', timestamp: '46af7641-c68e-11e8-9146-8343393a23eb' } 32 | ] 33 | }; 34 | render() { 35 | return ( 36 |
    37 | 38 | 50 |
    51 | ); 52 | } 53 | } 54 | 55 | export default App; 56 | -------------------------------------------------------------------------------- /00_1_intro_JS.md: -------------------------------------------------------------------------------- 1 | ## JS beyond JavaScript 2 | 3 | **JS CallStack** 4 | High level intro: Remember, first, that JS is a single-threaded language (this basically means that it can only handle one task at the time). 5 | The JS engine (example: Google V8 or SpiderMonkey) defines the Global Execution Context (GEC) like "the browser or Node" (in relation to where the code is executed), sets the Global Memory or Scope) and creates the Call Stack, which allows the interpreter to keep track of what happened, what is happening and what is going to happen. For more information about this abstract Data Type: [Stack]() 6 | 7 | An easy example to illustrate: 8 | 9 | ```javascript 10 | const name = 'Peter Pan'; 11 | 12 | function salutation() { 13 | alert(message()); 14 | } 15 | 16 | function message() { 17 | return 'Hello... ' + name; 18 | } 19 | 20 | salutation(); 21 | ``` 22 | 23 | * _Context_: browser (Firefox) 24 | * _Scope_: name, salutation() and message() are globally accessible 25 | * _CallStack_ 26 | 1. salutation() 27 | 2. message() 28 | As soon as message() resolves or finishes its execution, it´s removed from the stack (there´s no need to call what was executed) being salutation() the next function to be called, resolved and then, removed from the stack which will result in an empty Stack. 29 | 30 | One quick note about scope: 31 | Both, the functions and the variable of our example are part of the Window (global) context. 32 | You can check the Window´s context executing: 33 | 34 | ```console 35 | console.log(this); 36 | ``` 37 | 38 | However, something important to remind is that each time one of our function is invoked, a new context (functional context) is created for that particular function. -------------------------------------------------------------------------------- /examples/basic-react-example-state/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React + Redux + redux-thunk 23 | 24 | 25 | 28 |
    29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/basic-react-example-lifecycle/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React + Redux + redux-thunk 23 | 24 | 25 | 28 |
    29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/basic-react-example[map-with-key]/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React + Redux + redux-thunk 23 | 24 | 25 | 28 |
    29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/public/template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 15 | 24 | React + Redux + redux-thunk 25 | 26 | 27 | 30 |
    31 | 32 | 33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/webpack.config.prod.client.js: -------------------------------------------------------------------------------- 1 | const merge = require('webpack-merge'); 2 | const baseConfig = require('./webpack.config.js'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); 5 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 6 | 7 | const path = require('path'); 8 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 9 | 10 | const BrotliPlugin = require('brotli-webpack-plugin'); 11 | const CompressionPlugin = require('compression-webpack-plugin'); 12 | 13 | let pathsToClean = ['dist/', 'build/', 'public/']; 14 | 15 | let cleanOptions = { 16 | root: path.resolve(__dirname, '../'), 17 | exclude: ['template.html', 'manifest.json', 'favicon.ico'], 18 | verbose: true, 19 | dry: false 20 | }; 21 | 22 | const config = { 23 | name: 'client', 24 | target: 'web', 25 | mode: 'production', 26 | entry: { 27 | main: './src/index.js', 28 | other: './src/other.js' 29 | }, 30 | output: { 31 | path: path.resolve(__dirname, '../public'), 32 | // publicPath: '/', 33 | filename: './[name]-bundle.js' 34 | }, 35 | optimization: { 36 | minimizer: [new UglifyJsPlugin()] 37 | }, 38 | plugins: [ 39 | new CleanWebpackPlugin(pathsToClean, cleanOptions), 40 | new MiniCssExtractPlugin({ 41 | filename: '[name]-[contenthash].css' 42 | }), 43 | new OptimizeCssAssetsPlugin({ 44 | assetNameRegExp: /\.css$/g, 45 | cssProcessor: require('cssnano'), 46 | cssProcessorOptions: { discardComments: { removeAll: true } }, 47 | canPrint: true 48 | }), 49 | new CompressionPlugin({ 50 | algorithm: 'gzip' 51 | }), 52 | new BrotliPlugin() 53 | ] 54 | }; 55 | 56 | module.exports = merge(baseConfig, config); 57 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/public/template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 15 | 24 | Hola: React + Redux + redux-thunk 25 | 26 | 27 | 30 |
    31 | 32 | 33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/public/template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 15 | 24 | Hola: React + Redux + redux-thunk 25 | 26 | 27 | 30 |
    31 | 32 | 33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | import React from 'react'; 3 | import { BrowserRouter, Route } from 'react-router-dom'; 4 | import ReactDOM from 'react-dom'; 5 | import rootReducer from './reducers'; 6 | import { Provider } from 'react-redux'; 7 | import { createStore, applyMiddleware, compose } from 'redux'; 8 | //import ReduxPromise from 'redux-promise'; 9 | import reduxThunk from 'redux-thunk'; 10 | import App from './App'; 11 | 12 | const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 13 | 14 | const store = createStore( 15 | rootReducer, 16 | 17 | composeEnhancers(applyMiddleware(reduxThunk)) 18 | ); 19 | 20 | ReactDOM.render( 21 | 22 | 23 |
    24 |

    A

    25 | 26 |
    27 |
    28 |
    , 29 | document.getElementById('root') 30 | ); 31 | */ 32 | 33 | import React from 'react'; 34 | import { BrowserRouter, Route } from 'react-router-dom'; 35 | import ReactDOM from 'react-dom'; 36 | import rootReducer from './reducers'; 37 | import { Provider } from 'react-redux'; 38 | import { createStore, applyMiddleware, compose } from 'redux'; 39 | 40 | import '@babel/polyfill'; 41 | 42 | import reduxThunk from 'redux-thunk'; 43 | import App from './App'; 44 | 45 | const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 46 | 47 | const store = createStore( 48 | rootReducer, 49 | 50 | applyMiddleware(reduxThunk) 51 | ); 52 | 53 | ReactDOM.render( 54 | 55 | 56 |
    57 | 58 |
    59 |
    60 |
    , 61 | document.getElementById('root') 62 | ); 63 | 64 | var a = () => { 65 | console.log('Hello from the future!'); 66 | }; 67 | 68 | a(); 69 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 15 | 24 | React + Redux + redux-thunk 25 | 26 | 27 | 30 |
    31 | 32 | 33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/basic-webpack[default]/dist/bundle.js: -------------------------------------------------------------------------------- 1 | !(function(e) { 2 | var n = {}; 3 | function t(o) { 4 | if (n[o]) return n[o].exports; 5 | var r = (n[o] = { i: o, l: !1, exports: {} }); 6 | return e[o].call(r.exports, r, r.exports, t), (r.l = !0), r.exports; 7 | } 8 | (t.m = e), 9 | (t.c = n), 10 | (t.d = function(e, n, o) { 11 | t.o(e, n) || Object.defineProperty(e, n, { enumerable: !0, get: o }); 12 | }), 13 | (t.r = function(e) { 14 | 'undefined' != typeof Symbol && 15 | Symbol.toStringTag && 16 | Object.defineProperty(e, Symbol.toStringTag, { value: 'Module' }), 17 | Object.defineProperty(e, '__esModule', { value: !0 }); 18 | }), 19 | (t.t = function(e, n) { 20 | if ((1 & n && (e = t(e)), 8 & n)) return e; 21 | if (4 & n && 'object' == typeof e && e && e.__esModule) return e; 22 | var o = Object.create(null); 23 | if ( 24 | (t.r(o), 25 | Object.defineProperty(o, 'default', { enumerable: !0, value: e }), 26 | 2 & n && 'string' != typeof e) 27 | ) 28 | for (var r in e) 29 | t.d( 30 | o, 31 | r, 32 | function(n) { 33 | return e[n]; 34 | }.bind(null, r) 35 | ); 36 | return o; 37 | }), 38 | (t.n = function(e) { 39 | var n = 40 | e && e.__esModule 41 | ? function() { 42 | return e.default; 43 | } 44 | : function() { 45 | return e; 46 | }; 47 | return t.d(n, 'a', n), n; 48 | }), 49 | (t.o = function(e, n) { 50 | return Object.prototype.hasOwnProperty.call(e, n); 51 | }), 52 | (t.p = ''), 53 | t((t.s = 1)); 54 | })([ 55 | function(e, n) { 56 | console.log('app.js'), 57 | (e.exports.someFunction = () => { 58 | console.log('app.js > someFunction'); 59 | }); 60 | }, 61 | function(e, n, t) { 62 | 'use strict'; 63 | t.r(n); 64 | var o = t(0); 65 | console.log('index.js'), Object(o.someFunction)(); 66 | } 67 | ]); 68 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/server/server.js: -------------------------------------------------------------------------------- 1 | //const express = require('express'); 2 | import express from 'express'; 3 | 4 | //const expressStaticGzip = require('express-static-gzip'); 5 | import expressStaticGzip from 'express-static-gzip'; 6 | 7 | //const bodyParser = require('body-parser'); 8 | import bodyParser from 'body-parser'; 9 | 10 | const isProd = process.env.NODE_ENV === 'production'; 11 | 12 | //require('dotenv').config(); 13 | import dotenv from 'dotenv'; 14 | dotenv.config(); 15 | 16 | const isHtmlWebpackPlugin = process.env.WEBPACK_STATIC_HTML_BUILD; 17 | 18 | let webpackDevMiddleware, webpackHotMiddlware; 19 | 20 | const webpack = require('webpack'); 21 | 22 | if (!isProd) { 23 | const config = require('../config/webpack.config.dev.server.js'); 24 | const compiler = webpack(config); 25 | 26 | webpackDevMiddleware = require('webpack-dev-middleware')( 27 | compiler, 28 | config.devServer 29 | ); 30 | 31 | webpackHotMiddlware = require('webpack-hot-middleware')( 32 | compiler, 33 | config.devServer 34 | ); 35 | } else { 36 | const config = require('../config/webpack.config.prod.server.js'); 37 | webpack(config); 38 | } 39 | 40 | class RouterAndMiddlewares { 41 | constructor() { 42 | this.app = express(); 43 | this.initExpress(); 44 | this.middlewaresExpress(); 45 | this.initControllers(); 46 | this.start(); 47 | } 48 | 49 | initExpress() { 50 | this.app.set('port', 8080); 51 | } 52 | 53 | middlewaresExpress() { 54 | this.app.use(bodyParser.urlencoded({ extended: true })); 55 | this.app.use(bodyParser.json()); 56 | 57 | if (!isProd) { 58 | this.app.use(webpackDevMiddleware); 59 | this.app.use(webpackHotMiddlware); 60 | } 61 | 62 | /* 63 | const staticMiddleware = express.static('public'); 64 | this.app.use(staticMiddleware); 65 | */ 66 | 67 | this.app.use( 68 | expressStaticGzip('public', { 69 | enableBrotli: true, 70 | prefere: ['br'] 71 | }) 72 | ); 73 | } 74 | 75 | initControllers() { 76 | require('./BasicController.js')(this.app); 77 | } 78 | start() { 79 | let self = this; 80 | this.app.listen(this.app.get('port'), () => { 81 | console.log(`Server Listening for port: ${self.app.get('port')}`); 82 | }); 83 | } 84 | } 85 | 86 | new RouterAndMiddlewares(); 87 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nocra", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest", 8 | "start": "webpack-dev-server --config config/webpack.config.dev.js", 9 | "build": "webpack --config config/webpack.config.prod.js" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "dependencies": { 15 | "axios": "^0.18.0", 16 | "lodash": "^4.17.11", 17 | "nodemon": "^2.0.0", 18 | "react": "^16.6.3", 19 | "react-dom": "^16.6.3", 20 | "react-redux": "^7.0.0", 21 | "react-router-dom": "^5.0.0", 22 | "redux": "^4.0.1", 23 | "redux-thunk": "^2.3.0" 24 | }, 25 | "devDependencies": { 26 | "@babel/core": "^7.2.2", 27 | "@babel/plugin-proposal-class-properties": "^7.2.1", 28 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 29 | "@babel/plugin-transform-runtime": "^7.2.0", 30 | "@babel/polyfill": "^7.0.0", 31 | "@babel/preset-env": "^7.2.0", 32 | "@babel/preset-es2015": "^7.0.0-beta.53", 33 | "@babel/preset-react": "^7.0.0", 34 | "@babel/preset-stage-2": "^7.0.0", 35 | "babel-core": "7.0.0-bridge.0", 36 | "babel-jest": "^24.3.1", 37 | "babel-loader": "^8.0.4", 38 | "babel-plugin-async-to-promises": "^1.0.5", 39 | "babel-plugin-transform-async-to-promises": "^0.8.5", 40 | "babel-plugin-universal-import": "^4.0.0", 41 | "clean-webpack-plugin": "^3.0.0", 42 | "enzyme": "^3.8.0", 43 | "enzyme-adapter-react-16": "^1.7.1", 44 | "enzyme-to-json": "^3.3.5", 45 | "html-webpack-plugin": "^3.2.0", 46 | "identity-obj-proxy": "^3.0.0", 47 | "jest": "^24.3.1", 48 | "react-test-renderer": "^16.6.3", 49 | "regenerator-runtime": "^0.13.1", 50 | "webpack": "^4.27.1", 51 | "webpack-cli": "^3.1.2", 52 | "webpack-dev-server": "^3.1.10", 53 | "webpack-merge": "^4.1.5" 54 | }, 55 | "jest": { 56 | "collectCoverageFrom": ["src/**/*.{js,jsx,mjs}", "!**/node_modules/**"], 57 | "moduleNameMapper": { 58 | "\\.css$": "identity-obj-proxy" 59 | }, 60 | "transform": { 61 | "^.+\\.(js|jsx|mjs)$": "/node_modules/babel-jest" 62 | }, 63 | "coverageReporters": ["text-summary"], 64 | "setupFiles": ["/src/setupTests.js"] 65 | }, 66 | "browserslist": ["last 1 version", "> 1%", "IE 11", "IE 10", "IE 9"] 67 | } 68 | -------------------------------------------------------------------------------- /06_lifecycle-events.md: -------------------------------------------------------------------------------- 1 | ## Life-cycle events 2 | 3 | These are methods that allow us to execute certain functionality during the Component´s life-cycle (this is for `Class-based Components`. We will see as well `hooks` which are the "equivalent" for `Functional Components`). 4 | 5 | **Order of execution:** 6 | 7 | 1. `constructor(props)` > Initialization 8 | 2. `getDerivedStateFromProps(props, state)` > To update state based on changes on props 9 | 3. `shouldComponentUpdate(nextProps, nextState)` > We can stop or prevent unnecessary re-renders improving performance. 10 | 4. `render()` > Logic and return. It will render the particular component and its child. 11 | 5. `getSnapshotBeforeUpdate(prevProps, prevState)` > Returns a snapshot (object). 12 | 6. `componenDidMount()` > Here's where we cause or produce side-effects like fetching data (HTTP request) 13 | 7. `componentDidUpdate(prevProps, prevState, snapshot)` > Here's where we cause or produce side-effects like fetching data (HTTP request) 14 | 15 | **Deprecated life-cycles** 16 | 17 | 1. `componentWillMount()`: before the Component is inserted into the DOM 18 | 2. `componentWillReceiveProps()`: whenever the component is going to receive NEW props 19 | 3. `componentWillUnmount()`: before the Component is removed from the DOM 20 | 21 | 23 | 24 | ``` 25 | App > constructor() 26 | App > getDerivedStateFromProps() {} 27 | App > render() 28 | Child > render() 29 | App > componentDidMount() 30 | ``` 31 | And, if you click in the button (which updates the state property name in `App Component` and passes it to `Child as props`): 32 | 33 | ``` 34 | App > getDerivedStateFromProps() {} 35 | App > render() 36 | Child > shouldComponentUpdate() 37 | Child > render() 38 | Child > getSnapshotBeforeUpdate() 39 | Child > componentDidUpdate() 40 | {friend: "Peter"} 41 | ``` 42 | 43 | You will also see the following warnings that will prevent the execution of "the *will* life-cycles" 44 | 45 | ``` 46 | Warning: Unsafe legacy lifecycles will not be called for components using new component APIs. 47 | 48 | App uses getDerivedStateFromProps() but also contains the following legacy lifecycles: 49 | componentWillMount 50 | ``` 51 | 52 | ``` 53 | Warning: Unsafe legacy lifecycles will not be called for components using new component APIs. 54 | 55 | Child uses getSnapshotBeforeUpdate() but also contains the following legacy lifecycles: 56 | componentWillReceiveProps 57 | componentWillUpdate 58 | ``` 59 | 60 | 63 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/config/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HTMLWebpackPlugin = require('html-webpack-plugin'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | 5 | const webpack = require('webpack'); 6 | 7 | const isProd = process.env.NODE_ENV === 'production'; 8 | //console.log(isProd); 9 | 10 | require('dotenv').config(); 11 | const isHtmlWebpackPlugin = process.env.WEBPACK_STATIC_HTML_BUILD; 12 | 13 | const cssForDev = [ 14 | { loader: 'style-loader' }, 15 | { 16 | loader: 'css-loader', 17 | query: { 18 | modules: true, 19 | localIdentName: '[name]__[local]__[hash:base64:5]' 20 | } 21 | } 22 | ]; 23 | 24 | const cssForProd = [MiniCssExtractPlugin.loader, 'css-loader']; 25 | 26 | // Plugins 27 | 28 | let generalPlugins = [ 29 | new webpack.DefinePlugin({ 30 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) 31 | }) 32 | ]; 33 | 34 | const htmlWebpackPlugin = [ 35 | new HTMLWebpackPlugin({ 36 | template: './public/template.html' 37 | }) 38 | ]; 39 | 40 | if (isHtmlWebpackPlugin == 'true' || process.env.START == 'true') { 41 | generalPlugins = generalPlugins.concat(htmlWebpackPlugin); 42 | } 43 | 44 | //// Here´s the config 45 | 46 | module.exports = { 47 | entry: { 48 | main: './src/index.js', 49 | other: './src/other.js' 50 | }, 51 | output: { 52 | path: path.resolve(__dirname, '../public'), 53 | // publicPath: '/', 54 | filename: './[name]-bundle.js' 55 | }, 56 | stats: { 57 | colors: true 58 | }, 59 | module: { 60 | rules: [ 61 | { 62 | test: /\.js$/, 63 | exclude: /node_modules/, 64 | use: [ 65 | { 66 | loader: 'babel-loader', 67 | options: { 68 | presets: ['@babel/preset-env', '@babel/react'] 69 | } 70 | } 71 | ] 72 | }, 73 | { 74 | test: /\.css$/, 75 | use: isProd ? cssForProd : cssForDev 76 | }, 77 | { 78 | test: /\.(png|jpg|gif)$/, 79 | use: [ 80 | { 81 | loader: 'file-loader', 82 | options: { 83 | name: 'images/[name].[ext]' 84 | } 85 | } 86 | ] 87 | } 88 | ] 89 | }, 90 | optimization: { 91 | splitChunks: { 92 | chunks: 'all', 93 | cacheGroups: { 94 | vendor: { 95 | name: 'vendor', 96 | chunks: 'initial', 97 | minChunks: 2 98 | } 99 | } 100 | } 101 | }, 102 | plugins: generalPlugins 103 | }; 104 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/config/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HTMLWebpackPlugin = require('html-webpack-plugin'); 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 4 | 5 | const webpack = require('webpack'); 6 | 7 | const isProd = process.env.NODE_ENV === 'production'; 8 | //console.log(isProd); 9 | 10 | require('dotenv').config(); 11 | const isHtmlWebpackPlugin = process.env.WEBPACK_STATIC_HTML_BUILD; 12 | 13 | const cssForDev = [ 14 | { loader: 'style-loader' }, 15 | { 16 | loader: 'css-loader', 17 | query: { 18 | modules: true, 19 | localIdentName: '[name]__[local]__[hash:base64:5]' 20 | } 21 | } 22 | ]; 23 | 24 | const cssForProd = [MiniCssExtractPlugin.loader, 'css-loader']; 25 | 26 | // Plugins 27 | 28 | let generalPlugins = [ 29 | new webpack.DefinePlugin({ 30 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) 31 | }) 32 | ]; 33 | 34 | const htmlWebpackPlugin = [ 35 | new HTMLWebpackPlugin({ 36 | template: './public/template.html' 37 | }) 38 | ]; 39 | 40 | if (isHtmlWebpackPlugin == 'true' || process.env.START == 'true') { 41 | generalPlugins = generalPlugins.concat(htmlWebpackPlugin); 42 | } 43 | 44 | //// Here´s the config 45 | 46 | module.exports = { 47 | /* 48 | entry: { 49 | main: './src/index.js', 50 | other: './src/other.js' 51 | }, 52 | 53 | output: { 54 | path: path.resolve(__dirname, '../public'), 55 | // publicPath: '/', 56 | filename: './[name]-bundle.js' 57 | }, 58 | */ 59 | stats: { 60 | colors: true 61 | }, 62 | module: { 63 | rules: [ 64 | { 65 | test: /\.js$/, 66 | exclude: /node_modules/, 67 | use: [ 68 | { 69 | loader: 'babel-loader', 70 | options: { 71 | presets: ['@babel/preset-env', '@babel/react'] 72 | } 73 | } 74 | ] 75 | }, 76 | { 77 | test: /\.css$/, 78 | use: isProd ? cssForProd : cssForDev 79 | }, 80 | { 81 | test: /\.(png|jpg|gif)$/, 82 | use: [ 83 | { 84 | loader: 'file-loader', 85 | options: { 86 | name: 'images/[name].[ext]' 87 | } 88 | } 89 | ] 90 | } 91 | ] 92 | }, 93 | optimization: { 94 | splitChunks: { 95 | chunks: 'all', 96 | cacheGroups: { 97 | vendor: { 98 | name: 'vendor', 99 | chunks: 'initial', 100 | minChunks: 2 101 | } 102 | } 103 | } 104 | }, 105 | plugins: generalPlugins 106 | }; 107 | -------------------------------------------------------------------------------- /07_conditional-rendering.md: -------------------------------------------------------------------------------- 1 | ## Conditional Rendering 2 | 3 | Previously, we saw some "conditional logic" like the "ternary operator". Now, we are going to resume this subject seeing different ways to render content in relation to x-criteria. 4 | 5 | #### State and Class 6 | 7 | In the first cases, we are going to be using our state property `conditionIs` to show one message or other. 8 | 9 | **if/else** - regular if/else inside render() or custom method 10 | 11 | ```javascript 12 | import React, { Component } from 'react'; 13 | 14 | class App extends Component { 15 | state = { 16 | conditionIs: true 17 | }; 18 | 19 | render() { 20 | const { conditionIs } = this.state; 21 | 22 | let jSx; 23 | if (conditionIs) { 24 | jSx = `I've a cristal clear state... I'm ${conditionIs}`; 25 | } else { 26 | jSx = `I'm ${conditionIs}`; 27 | } 28 | 29 | return
    {jSx}
    ; 30 | } 31 | } 32 | 33 | export default App; 34 | ``` 35 | 36 | **if/else** - condition ? () : () 37 | 38 | ```javascript 39 | render() { 40 | const { conditionIs } = this.state; 41 | 42 | return ( 43 |
    44 | {conditionIs 45 | ? `I've a cristal clear state... I'm ${conditionIs}` 46 | : `I'm ${conditionIs}`} 47 |
    48 | ); 49 | } 50 | } 51 | ``` 52 | 53 | **Ternary operator** 54 | 55 | ```javascript 56 | render() { 57 | const { conditionIs } = this.state; 58 | 59 | let jSx = conditionIs 60 | ? `I've a cristal clear state... I'm ${conditionIs}` 61 | : `I'm ${conditionIs}`; 62 | 63 | return
    {jSx}
    ; 64 | } 65 | ``` 66 | 67 | **if &&** (short-circuit evaluation) 68 | 69 | ```javascript 70 | render() { 71 | const { conditionIs } = this.state; 72 | 73 | return ( 74 |
    75 | {conditionIs && `I've a cristal clear state... I'm ${conditionIs}`} 76 |
    77 | ); 78 | } 79 | } 80 | ``` 81 | 82 | #### Props and Functional component 83 | 84 | **if > return** - if x, return z 85 | 86 | ```javascript 87 | import React from 'react'; 88 | 89 | const Child = props => { 90 | if (!props.conditionIs) { 91 | return null; 92 | } 93 | 94 | return
    Im Child! {props.conditionIs}
    ; 95 | }; 96 | 97 | const App = () => ( 98 |
    99 | Im App! 100 | 101 |
    102 | ); 103 | 104 | export default App; 105 | ``` 106 | 107 | Note: You will see that some people return empty elements like `` or `
    `. This is totally valid, however, in most cases you don´t want to "return something" (aka, add some element to the DOM) so, start always returning `null`, and switch to elements in case you want to render and show a particular message to the user. 108 | -------------------------------------------------------------------------------- /04_methods.md: -------------------------------------------------------------------------------- 1 | ## Methods 2 | 3 | Let´s grab the previous example and use a `Global Event Handler` (for this case, onClick) with setState() and a custom method. 4 | 5 | Note: In React events (like onClick), methods and component´s attributes (aka, props) are named using `lower camelCase`. 6 | 7 | ### Setting state with onClick 8 | 9 | ```javascript 10 | class App extends Component { 11 | state = { 12 | yourName: 'Peter Pan' 13 | }; 14 | 15 | render() { 16 | return ( 17 |
    18 |

    {`Hello ${this.state.yourName}`}

    19 |
    this.setState({ yourName: 'Wendy' })}> 20 | Change name to Wendy on clicking... 21 |
    22 |
    23 | ); 24 | } 25 | } 26 | ``` 27 | 28 | ### Setting state with custom method 29 | 30 | ```javascript 31 | class App extends Component { 32 | state = { 33 | yourName: 'Peter Pan' 34 | }; 35 | 36 | updateStateProperty = (stateProperty, statePropertyValue) => { 37 | this.setState({ [stateProperty]: statePropertyValue }); 38 | }; 39 | 40 | render() { 41 | return ( 42 |
    43 |

    {`Hello ${this.state.yourName}`}

    44 |
    this.updateStateProperty('yourName', 'Wendy')}> 45 | Change state... 46 |
    47 |
    48 | ); 49 | } 50 | } 51 | ``` 52 | 53 | ### Setting state with custom method passing it down 54 | 55 | App.js 56 | 57 | ```javascript 58 | import React, { Component } from 'react'; 59 | import Child from './Child'; 60 | 61 | class App extends Component { 62 | state = { 63 | yourName: 'Peter Pan' 64 | }; 65 | 66 | updateStateProperty = (stateProperty, statePropertyValue) => { 67 | this.setState({ [stateProperty]: statePropertyValue }); 68 | }; 69 | 70 | render() { 71 | return ( 72 |
    73 |

    {`Hello ${this.state.yourName}`}

    74 | 75 | Change state... 76 | 77 |
    78 | ); 79 | } 80 | } 81 | 82 | export default App; 83 | ``` 84 | 85 | Child.js 86 | 87 | ```javascript 88 | import React from 'react'; 89 | 90 | const Child = props => ( 91 |
    92 |
    props.onUpdateStateProperty('yourName', 'Wendy')}> 93 | Change state... 94 |
    95 |
    96 | ); 97 | 98 | export default Child; 99 | ``` 100 | 101 | Notes: 102 | In `App.js` we pass a reference to the function updateStateProperty `onUpdateStateProperty={this.updateStateProperty}` as props to `Child.js` where we are going to execute the function with the proper arguments `onClick={() => props.onUpdateStateProperty('yourName', 'Wendy')}` 103 | -------------------------------------------------------------------------------- /notesToPlace_primitive-and-reference-types.md: -------------------------------------------------------------------------------- 1 | **Primitive and reference types** 2 | I´m going to suppose that you are familiar with the concept of "Data Types" (string, number, array, boolean, null, undefined, symbol, object) 3 | Our "data" can be classified as Primitive or Reference in relation to _where_ and _how_ it´s stored in memory. 4 | 5 | * Variables that hold "just one value" are stored in the "stack" (memory, faster but less storage) and every time we pass them to, for example a function, we pass the value. 6 | * Variables that hold "multiple values" (like objects and arrays) are stored in the "heap" (memory, slower but more storage) and are passed as reference: we don´t pass the value, if not, a pointer that is going to reference to that value. 7 | 8 | Primitive Types are copied by value 9 | 10 | Primitive Type: string example. 11 | We declare a variable and initialize it with the value of "Peter". 12 | Then, we declare an initialize a new variable with the VALUE of the previous one, name. 13 | If we decide to change the value of name, name will hold the new data but name1 will keep the value that we passed: "Peter". 14 | 15 | ``` 16 | let name = "Peter"; 17 | let name1 = name; 18 | name = "Pan"; 19 | 20 | console.log('name ' + name); 21 | console.log('name1 ' + name1); 22 | ``` 23 | 24 | Result: 25 | 26 | ``` 27 | name Pan 28 | name1 Peter 29 | ``` 30 | 31 | Remember: we are copying the value that we stored in `name` and set it as the value of `name1`. Two different variables holding two different values. 32 | 33 | Now, let´s try to do something similar with a Reference Type. 34 | 35 | ``` 36 | let person = { name: "Peter"}; 37 | 38 | let name = person.name; 39 | 40 | person.name = "Pan"; 41 | 42 | let name1 = name; 43 | 44 | let name2 = person; 45 | 46 | console.log(person); 47 | 48 | console.log('name ' + name); 49 | console.log('name1 ' + name1); 50 | 51 | console.log('name2 ' + JSON.stringify(person)); 52 | ``` 53 | 54 | Result: 55 | 56 | ``` 57 | { name: 'Pan' } 58 | name Peter 59 | name1 Peter 60 | name2 {"name":"Pan"} 61 | ``` 62 | 63 | Short explanation: 64 | 65 | 1. We declare an initialize the variable person with an object. 66 | 2. `Variable name` is initialized with the value of the property name of the object person. This value is a string, so it will be passed by value. 67 | 3. We change the value of the `property name` of the object person to `string "Pan"` 68 | 4. We declare and initialize the `variable name1` with the value of the variable name (by value) 69 | 5. We declare and initialize the `variable name2` with person (by reference). 70 | 71 | Primitives are compared by value. 72 | 73 | ``` 74 | var a = 1; 75 | var b = 1; 76 | a === b; 77 | ``` 78 | 79 | This returns `'true'` 80 | 81 | However, this is false for Reference (where the comparison is between the spaces in the heap that each one is occupying) 82 | 83 | ``` 84 | var a = { a: 1}; 85 | var b = { a: 1}; 86 | a === b; 87 | ``` 88 | 89 | This returns `'false'` 90 | -------------------------------------------------------------------------------- /01_1_elements.md: -------------------------------------------------------------------------------- 1 | ## React Elements 2 | 3 | **createElement()** 4 | 5 | Returns a JavaScript object 6 | It takes 3 arguments: 7 | 8 | 1. element 9 | 2. attributes 10 | 3. content or element´s children 11 | 12 | Example: 13 | 14 | ```javascript 15 | const element = React.createElement( 16 | 'div', 17 | null, 18 | React.createElement('strong', null, 'Hello world!') 19 | ); 20 | ``` 21 | 22 | *Note:* We can pass multiple parameters as the last argument. Behind the scenes, `React` will "wrap them" in an array. 23 | 24 | Example: 25 | ```javascript 26 | ... 27 | React.createElement('div', null, 'Hello world!', ' More 1...', ' More 2...') 28 | ... 29 | ``` 30 | 31 | In our examples, if we log `element` we will have one case where the value of the key `children` will be a `string` and the other an `array of strings` 32 | 33 | ```javascript 34 | props: 35 | children: "Hello world!" 36 | 37 | props: 38 | children: (3) ["Hello world!", " More 1...", " More 2..."] 39 | ``` 40 | 41 | Alternatively, we can pass an `object` as the *second argument* containing: `attributes` and the own `content` as the `value` of the children's key. 42 | Example: 43 | ```javascript 44 | const element = React.createElement( 45 | 'div', 46 | null, 47 | React.createElement('div', { role: 'contentinfo', className: 'this-is-a-div', children: ['Hi',' Hola'] }) 48 | ); 49 | ``` 50 | 51 | **ReactDOM.render()** 52 | 53 | Let´s first `render` our previous element. 54 | 55 | ```javascript 56 | const element = React.createElement( 57 | 'div', 58 | null, 59 | React.createElement('strong', null, 'Hello world!') 60 | ); 61 | 62 | ReactDOM.render(element, document.getElementById('root')); 63 | ``` 64 | 65 | If we inspect our `html` we will see our DOM node... 66 | 67 | ```html 68 | 69 |
    70 |
    Hello world!
    71 |
    72 | 73 | ``` 74 | 75 | Another example (with `components` not elements) 76 | 77 | Example: `src/index.js` 78 | 79 | ```javascript 80 | ReactDOM.render( 81 | 82 | 83 | , 84 | document.getElementById('root') 85 | ); 86 | ``` 87 | 88 | *Note:* Remember `React Apps` **usually** have a `single root element`. 89 | 90 | File: `public/index.html` 91 | 92 | ```html 93 |
    94 | ``` 95 | 96 | ### Elements 97 | 98 | As we saw previously, we create elements through `React.createElement()`. 99 | An element is an object that describes what we want to show in the screen. 100 | Well, it is (in fact) an object representation of a DOM node. 101 | 102 | ```javascript 103 | const element =
    Im an element!
    ; 104 | ``` 105 | 106 | Through components (we will cover this on the next chapter) we return the created elements. Let´s go back to our `Hello world!` example... 107 | 108 | ```javascript 109 | const element = React.createElement( 110 | 'div', 111 | null, 112 | React.createElement('strong', null, 'Hello world!') 113 | ); 114 | 115 | HelloWorld = () => element; 116 | 117 | ReactDOM.render(, document.getElementById('root')); 118 | ``` 119 | -------------------------------------------------------------------------------- /00_3_intro_es2015.md: -------------------------------------------------------------------------------- 1 | ## es2015 or ES6 2 | 3 | `.map(), .reduce() and .filter()` 4 | 5 | **.reduce()** 6 | 7 | `myArray.reduce(callback[, initialValue])` 8 | 9 | It takes a collection of data and reduce it to a single value. 10 | It´s the base of one of the vital parts of Redux´s flow: reducers. 11 | 12 | Example: reduce years collection into TOTAL years 13 | 14 | ```javascript 15 | const friends = [ 16 | { name: 'Peter', age: 30 }, 17 | { name: 'Tinkerbell', age: 100 }, 18 | { name: 'Wendy', age: 31 } 19 | ]; 20 | 21 | friends.reduce((totalYear, eachAge) => { 22 | return (addFriendsAge = totalYear + eachAge.age); 23 | }, 0); 24 | 25 | console.log(addFriendsAge); 26 | // 161 27 | ``` 28 | 29 | Short explanation... 30 | When we call reduce() we start from 0 (try changing 0 to 100). 31 | The first time our function is called, totalYear (or accumulator) will have the value of 0 and eachAge 30. 32 | The return of our function is a new variable (addFriendsAge) with the sum of all ages. 33 | 34 | One comment about `return`. 35 | If we are returning in one line we can do... 36 | 37 | `renderMessage = message => message;` 38 | 39 | ```javascript 40 | renderMessage = message => message; 41 | 42 | ... 43 | 44 | render() { 45 | return ( 46 |
    {this.renderMessage('Hi')}
    47 | ); 48 | } 49 | ``` 50 | 51 | ... or ... `renderMessage = message => { return message; };` or the same, `renderMessage = message => { return
    {message}
    ; };` 52 | 53 | For multilines use `()` 54 | 55 | ```javascript 56 | renderMessage = message => { 57 | return ( 58 |
    59 | My message:
    {message}
    60 |
    61 | ); 62 | }; 63 | ``` 64 | 65 | **.map()** 66 | 67 | `const myArrayElements = myArray.map(function callback(currentValue[, index[, array]]) { // element to return }[, thisArg])` 68 | 69 | Given an array, it generates a new one (just for clarity allow me to repeat, new array) as the result of executing the callback function on each element of the array. 70 | 71 | Example: map an array and retrieve a new array with the results assigned to a variable 72 | 73 | ```javascript 74 | const friends = [ 75 | { name: 'Peter', age: 30 }, 76 | { name: 'Tinkerbell', age: 100 }, 77 | { name: 'Wendy', age: 31 } 78 | ]; 79 | 80 | const friendsNames = friends.map(eachFriend => eachFriend.name); 81 | 82 | console.log(friendsNames); 83 | // Array(3) [ "Peter", "Tinkerbell", "Wendy" ] 84 | ``` 85 | 86 | **.filter()** 87 | 88 | `var myArrayElements = myArray.filter(callback(element[, index[, array]])[, thisArg])` 89 | 90 | Given an array, it generates a new one with the elements that meet the criteria of the function logic. 91 | 92 | Example: filter and retrieve all the elements which property name is NOT Wendy 93 | 94 | ```javascript 95 | const friends = [ 96 | { name: 'Peter', age: 30 }, 97 | { name: 'Tinkerbell', age: 100 }, 98 | { name: 'Wendy', age: 31 } 99 | ]; 100 | 101 | const friendsFiltered = friends.filter(friend => friend.name != 'Wendy'); 102 | 103 | console.log(friendsFiltered); 104 | /* 105 | (2) […] 106 | 0: Object { name: "Peter", age: 30 } 107 | 1: Object { name: "Tinkerbell", age: 100 } 108 | */ 109 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React 2 | 3 | [![Greenkeeper badge](https://badges.greenkeeper.io/alpersonalwebsite/react.svg)](https://greenkeeper.io/) 4 | [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) 5 | 6 | **Original MOTTO:** An easy way to learn React through examples. 7 | 8 | **Updated MOTTO:** Learning React topic by topic. 9 | 10 | ## Before starting 11 | 12 | --- 13 | 14 | *2/21/19 UPDATE*: 15 | Many things happened in `React` and its ecosystem. I will try to update the sections to `React 16.8.\*` (`Hooks` and some interesting `new APIs`) and go deeper in the “Life cycle” paragraph for class-based Components. Also, I will be splitting sections in sub-sections for better understanding and proper grouping. 16 | 17 | --- 18 | 19 | After several years of contributing, mentoring and working with `JS` and `React`, I decided to “put together” some notes linked to recurrent doubts and obstacles that friends and co-workers have to face daily. 20 | 21 | This is a pure practical guide (*ps*, it was at the beginning): please, keep the `practical intention` present during the course of these "shared notes"; I don´t have the intent of challenging the great and plentiful coaching classes; neither the books/"white papers" that today, you can easily find anywhere (starting with the own Facebook´s proprietary documentation). 22 | 23 | My aim, as I stated before (even with the latests addons and updates), is -still- clearly pragmatic. You will see some concepts and technicalities (as general and well-needed context) but you should (perhaps must) complement this "joint exercise" with other materials (I try to avoid quoting or referencing given that, an important part of your training is discovering good sources and picking those that satisfy your own and extremely personal "way to learn". 24 | However, taking a look the the mother source will not hurt you: [react](https://github.com/facebook/react)). 25 | 26 | ## Getting Started 27 | 28 | ### Pre-requisites 29 | 30 | You DO need to have an intermediate knowledge of `JavaScript` and, preferably, some exposure to [es2015 or ES6](http://es6-features.org). 31 | Even when "more complex topics" (not ordinary ones) are addressed as needed as part of the "lessons" (for example *leaks*, *currying*) not having an underlying `JS` base at all will generate more doubts and it could guide you to frustration, and ultimately, a premature failure. 32 | If you don´t have experience with `JavaScript`, some familiarity with `Functional Programming` and `Prototypes`... Please, first resolve the context of `this` and `then` come back (btw, if this made you smile, you should be good). 33 | 34 | Before proceeding with the tutorial, be sure that you have installed or, install... 35 | 36 | **Required** 37 | 38 | * [Node.js](https://nodejs.org/en/download/) 39 | * Package manager (`npm` which comes with `Node` or `yarn`) 40 | 41 | *Note:* packages, dependencies, libraries... are going to be referenced on-demand. Those whose scope is bigger will be addressed in [09_packages](./09_packages.md) 42 | 43 | **Recommended** 44 | 45 | * For Windows users: `Git bash` https://git-scm.com/downloads as a `CMD` replace, or, `PowerShell` 46 | 47 | **Alternatives** 48 | 49 | * yarn https://yarnpkg.com/lang/en/docs/install/ 50 | 51 | Alternative to `npm`. I will be using `yarn` 52 | (At the moment of writing this `doc` there are no major differences between the two, as it used to...) 53 | 54 | Learn more about the [npm registry](https://docs.npmjs.com/misc/registry) consumed by both, `yarn` and `npm` -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nocra", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": 8 | "jest --env=jsdom --watchAll --colors --config=config/jest/jest.config.json --rootDir", 9 | "start": 10 | "cross-env START='true' NODE_ENV=development webpack-dev-server --config config/webpack.config.dev.client.js", 11 | "build:dev": 12 | "cross-env NODE_ENV=development webpack --config config/webpack.config.dev.client.js", 13 | "build": 14 | "cross-env NODE_ENV=production webpack --config config/webpack.config.prod.js", 15 | "build:server": 16 | "cross-env NODE_ENV=production webpack --config config/webpack.config.prod.server.js --env.NODE_ENV=production --watch", 17 | "dev": "cross-env NODE_ENV=development node server/index.js", 18 | "build:server:flex": 19 | "cross-env nodemon --watch build build/server-prod-bundle.js", 20 | "prod": "cross-env NODE_ENV=production node build/server-prod-bundle.js" 21 | }, 22 | "keywords": [], 23 | "author": "", 24 | "license": "ISC", 25 | "dependencies": { 26 | "@emotion/core": "^10.0.5", 27 | "@emotion/styled": "^10.0.5", 28 | "axios": "^0.18.0", 29 | "dotenv": "^8.0.0", 30 | "express-static-gzip": "^1.1.3", 31 | "lodash": "^4.17.11", 32 | "nodemon": "^2.0.0", 33 | "react": "^16.6.3", 34 | "react-dom": "^16.6.3", 35 | "react-redux": "^7.0.0", 36 | "react-router-dom": "^5.0.0", 37 | "redux": "^4.0.1", 38 | "redux-thunk": "^2.3.0" 39 | }, 40 | "devDependencies": { 41 | "@babel/core": "^7.2.2", 42 | "@babel/plugin-proposal-class-properties": "^7.2.1", 43 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 44 | "@babel/plugin-transform-runtime": "^7.2.0", 45 | "@babel/polyfill": "^7.0.0", 46 | "@babel/preset-env": "^7.2.0", 47 | "@babel/preset-es2015": "^7.0.0-beta.53", 48 | "@babel/preset-react": "^7.0.0", 49 | "@babel/preset-stage-2": "^7.0.0", 50 | "@babel/register": "^7.0.0", 51 | "babel-core": "7.0.0-bridge.0", 52 | "babel-jest": "^24.3.1", 53 | "babel-loader": "^8.0.4", 54 | "babel-plugin-async-to-promises": "^1.0.5", 55 | "babel-plugin-emotion": "^10.0.5", 56 | "babel-plugin-transform-async-to-promises": "^0.8.5", 57 | "babel-plugin-universal-import": "^4.0.0", 58 | "brotli-webpack-plugin": "^1.0.0", 59 | "clean-webpack-plugin": "^3.0.0", 60 | "compression-webpack-plugin": "^2.0.0", 61 | "cross-env": "^6.0.0", 62 | "css-loader": "^3.0.0", 63 | "enzyme": "^3.8.0", 64 | "enzyme-adapter-react-16": "^1.7.1", 65 | "enzyme-to-json": "^3.3.5", 66 | "file-loader": "^4.0.0", 67 | "html-webpack-plugin": "^3.2.0", 68 | "identity-obj-proxy": "^3.0.0", 69 | "jest": "^24.3.1", 70 | "jest-cli": "^24.3.1", 71 | "jest-watch-typeahead": "^0.3.0", 72 | "mini-css-extract-plugin": "^0.7.0", 73 | "optimize-css-assets-webpack-plugin": "^5.0.1", 74 | "react-test-renderer": "^16.6.3", 75 | "regenerator-runtime": "^0.13.1", 76 | "style-loader": "^0.23.1", 77 | "uglifyjs-webpack-plugin": "^2.0.1", 78 | "webpack": "^4.27.1", 79 | "webpack-bundle-analyzer": "^3.0.3", 80 | "webpack-cli": "^3.1.2", 81 | "webpack-dev-middleware": "^3.4.0", 82 | "webpack-dev-server": "^3.1.10", 83 | "webpack-hot-middleware": "^2.24.3", 84 | "webpack-merge": "^4.1.5", 85 | "webpack-node-externals": "^1.7.2" 86 | }, 87 | "browserslist": ["last 1 version", "> 1%", "IE 11", "IE 10", "IE 9"] 88 | } 89 | -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/server/server.js: -------------------------------------------------------------------------------- 1 | //const express = require('express'); 2 | import express from 'express'; 3 | 4 | //const expressStaticGzip = require('express-static-gzip'); 5 | import expressStaticGzip from 'express-static-gzip'; 6 | 7 | //const bodyParser = require('body-parser'); 8 | import bodyParser from 'body-parser'; 9 | 10 | const isProd = process.env.NODE_ENV === 'production'; 11 | 12 | //require('dotenv').config(); 13 | import dotenv from 'dotenv'; 14 | dotenv.config(); 15 | 16 | import webpackHotServerMiddleware from 'webpack-hot-server-middleware'; 17 | 18 | const isHtmlWebpackPlugin = process.env.WEBPACK_STATIC_HTML_BUILD; 19 | 20 | let webpackDevMiddleware, webpackHotMiddlware, compiler; 21 | 22 | const webpack = require('webpack'); 23 | import devClientConfiguration from '../config/webpack.config.dev.client.js'; 24 | import devServerConfiguration from '../config/webpack.config.dev.server.js'; 25 | 26 | import prodClientConfiguration from '../config/webpack.config.prod.client.js'; 27 | import prodServerConfiguration from '../config/webpack.config.prod.server.js'; 28 | 29 | console.log('ENNNNNNNNNNNNNNNNNNNNNNNNNNN', typeof isProd); 30 | 31 | if (isProd === false) { 32 | //const config = require('../config/webpack.config.dev.server.js'); 33 | //const devClientConfiguration = require('../config/webpack.config.dev.client.js'); 34 | //const devServerConfiguration = require('../config/webpack.config.dev.server.js'); 35 | 36 | compiler = webpack([devClientConfiguration, devServerConfiguration]); 37 | 38 | //console.log(compiler); 39 | 40 | webpackDevMiddleware = require('webpack-dev-middleware')( 41 | compiler, 42 | devClientConfiguration.devServer 43 | ); 44 | 45 | webpackHotMiddlware = require('webpack-hot-middleware')( 46 | compiler.compilers[0], 47 | devClientConfiguration.devServer 48 | ); 49 | } else { 50 | console.log('WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW'); 51 | //const config = require(); 52 | webpack([prodClientConfiguration, prodServerConfiguration]); 53 | } 54 | 55 | class RouterAndMiddlewares { 56 | constructor() { 57 | this.app = express(); 58 | this.initExpress(); 59 | this.middlewaresExpress(); 60 | this.initControllers(); 61 | this.start(); 62 | } 63 | 64 | initExpress() { 65 | this.app.set('port', 8080); 66 | } 67 | 68 | middlewaresExpress() { 69 | this.app.use(bodyParser.urlencoded({ extended: true })); 70 | this.app.use(bodyParser.json()); 71 | 72 | if (!isProd) { 73 | console.log(1111111111111111111111, webpackDevMiddleware); 74 | this.app.use(webpackDevMiddleware); 75 | this.app.use(webpackHotMiddlware); 76 | this.app.use(webpackHotServerMiddleware(compiler)); 77 | } 78 | 79 | /* 80 | const staticMiddleware = express.static('public'); 81 | this.app.use(staticMiddleware); 82 | */ 83 | 84 | this.app.use( 85 | expressStaticGzip('public', { 86 | enableBrotli: true, 87 | prefere: ['br'] 88 | }) 89 | ); 90 | } 91 | 92 | initControllers() { 93 | require('./BasicController.js')(this.app); 94 | } 95 | start() { 96 | let self = this; 97 | this.app.listen(this.app.get('port'), () => { 98 | console.log(`Server Listening for port: ${self.app.get('port')}`); 99 | }); 100 | } 101 | } 102 | 103 | new RouterAndMiddlewares(); 104 | 105 | /* 106 | module.exports = app => { 107 | return new RouterAndMiddlewares(app); 108 | }; 109 | */ 110 | -------------------------------------------------------------------------------- /00_2_intro_JS-patterns.md: -------------------------------------------------------------------------------- 1 | ## Functional Programming 2 | 3 | ### HOF: Higher Order Function 4 | Is a `function` that takes a function as an argument AND/OR returns a function. 5 | 6 | *Basic example:* function that returns (or creates) a new function. 7 | 8 | ```javascript 9 | multiplyNumbers = theFirstNumber => { 10 | return theSecondNumber => theSecondNumber * theFirstNumber; 11 | }; 12 | 13 | let multiplyNumbers30 = multiplyNumbers(30); 14 | 15 | // console.log(multiplyNumbers30); 16 | console.log(typeof multiplyNumbers30); 17 | // function 18 | 19 | console.log(multiplyNumbers30(2)); 20 | // 60 21 | 22 | console.log(typeof multiplyNumbers30(2)); 23 | // number 24 | ``` 25 | 26 | --- 27 | 28 | ### Immutability 29 | * Mutable data that CAN be modified after creation 30 | * Immutable can NOT be modified 31 | 32 | *Mutable example*: as you can see, when we `push()` we are modifying the original source, `arr1` 33 | ```javascript 34 | const arr1 = [1,2,3] 35 | 36 | const arr2 = arr1 37 | 38 | arr2.push(4) 39 | 40 | console.log(arr1, arr2) 41 | console.log(arr1 == arr2, arr1 === arr2) 42 | ``` 43 | 44 | Result: 45 | ```javascript 46 | [1, 2, 3, 4] 47 | [1, 2, 3, 4] 48 | true 49 | true 50 | ``` 51 | 52 | *Immutable example*: with the spread operator we are spreading all the values of `arr1` in a new array 53 | ```javascript 54 | const arr1 = [1,2,3] 55 | 56 | const arr2 = [...arr1] 57 | 58 | arr2.push(4) 59 | 60 | console.log(arr1, arr2) 61 | console.log(arr1 == arr2, arr1 === arr2) 62 | ``` 63 | 64 | Result: 65 | ```javascript 66 | [1, 2, 3] 67 | [1, 2, 3, 4] 68 | false 69 | false 70 | ``` 71 | 72 | *Important note*: You will find several tutorials (and libraries) offering methods to avoid mutating data. Some of them, using the same naming (`push`) which can be confusing, especially at the beginning. Let's see this case to dispel any possible doubt during your research. 73 | 74 | ```javascript 75 | /* If your prefer fat arrow fn 76 | const push = element => arr => { 77 | let tempArr = [...arr] 78 | tempArr.push(element) 79 | return tempArr 80 | } 81 | */ 82 | 83 | function push(element) { 84 | return function (arr) { 85 | let tempArr = [...arr] 86 | tempArr.push(element) 87 | return tempArr 88 | } 89 | } 90 | 91 | const arr1 = [1,2,3] 92 | const arr2 = arr1 93 | const arr3 = push(5)(arr1) 94 | 95 | console.log(arr1, arr2, arr3) 96 | ``` 97 | 98 | Result: 99 | ```javascript 100 | [1, 2, 3] 101 | [1, 2, 3] 102 | [1, 2, 3, 5] 103 | ``` 104 | 105 | The method `push()()` is a `curried function` (*a function that takes multiple arguments one at the time: btw, we will see this topic in depth*). First, we are passing the element that we want to append in our new array; second, the original array. 106 | 107 | Here's the important part. In our example, `push()` is a function defined in the `global scope` while `[].push` a method of the Array data type. 108 | 109 | Try... 110 | ```javascript 111 | console.log(push()) 112 | console.log([].push) 113 | ``` 114 | 115 | Result: 116 | ```javascript 117 | function (arr) { 118 | let tempArr = [...arr] 119 | tempArr.push(element) 120 | return tempArr 121 | } 122 | function push() { [native code] } 123 | ``` 124 | 125 | 126 | 127 | In most of the cases, using the `spread operator (...)` will be enough (even for nested arrays). 128 | 129 | ```javascript 130 | const arr1 = [1, [2,3, [4]], 5, [6, [7]]] 131 | const arr2 = [...arr1] 132 | 133 | console.log(arr1, arr2) 134 | ``` 135 | 136 | ```javascript 137 | [1, [2, 3, [4]], 5, [6, [7]]] 138 | [1, [2, 3, [4]], 5, [6, [7]]] 139 | ``` -------------------------------------------------------------------------------- /examples/react-redux-webpack-client-server-scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nocra", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --env=jsdom --watchAll --colors --config=config/jest/jest.config.json --rootDir", 8 | "start": "cross-env START='true' NODE_ENV=development webpack-dev-server --config config/webpack.config.dev.client.js", 9 | "build:dev": "cross-env NODE_ENV=development webpack --config config/webpack.config.dev.client.js", 10 | "build": "cross-env NODE_ENV=production webpack --config config/webpack.config.prod.js", 11 | "build:server": "cross-env NODE_ENV=production webpack --config config/webpack.config.prod.server.js --env.NODE_ENV=production --watch", 12 | "dev": "cross-env NODE_ENV=development nodemon --watch config --watch server --inspect server/index.js", 13 | "build:server:flex": "cross-env nodemon --watch build build/server-prod-bundle.js", 14 | "prod": "cross-env NODE_ENV=production node server/index.js" 15 | }, 16 | "keywords": [], 17 | "author": "", 18 | "license": "ISC", 19 | "dependencies": { 20 | "@emotion/core": "^10.0.5", 21 | "@emotion/styled": "^10.0.5", 22 | "axios": "^0.18.0", 23 | "dotenv": "^8.0.0", 24 | "express-static-gzip": "^1.1.3", 25 | "lodash": "^4.17.11", 26 | "nodemon": "^2.0.0", 27 | "react": "^16.6.3", 28 | "react-dom": "^16.6.3", 29 | "react-redux": "^7.0.0", 30 | "react-router-dom": "^5.0.0", 31 | "redux": "^4.0.1", 32 | "redux-thunk": "^2.3.0", 33 | "webpack-hot-server-middleware": "^0.6.0" 34 | }, 35 | "devDependencies": { 36 | "@babel/core": "^7.2.2", 37 | "@babel/plugin-proposal-class-properties": "^7.2.1", 38 | "@babel/plugin-syntax-dynamic-import": "^7.2.0", 39 | "@babel/plugin-transform-runtime": "^7.2.0", 40 | "@babel/polyfill": "^7.0.0", 41 | "@babel/preset-env": "^7.2.0", 42 | "@babel/preset-es2015": "^7.0.0-beta.53", 43 | "@babel/preset-react": "^7.0.0", 44 | "@babel/preset-stage-2": "^7.0.0", 45 | "@babel/register": "^7.0.0", 46 | "babel-core": "7.0.0-bridge.0", 47 | "babel-jest": "^24.3.1", 48 | "babel-loader": "^8.0.4", 49 | "babel-plugin-async-to-promises": "^1.0.5", 50 | "babel-plugin-emotion": "^10.0.5", 51 | "babel-plugin-transform-async-to-promises": "^0.8.5", 52 | "babel-plugin-universal-import": "^4.0.0", 53 | "brotli-webpack-plugin": "^1.0.0", 54 | "clean-webpack-plugin": "^3.0.0", 55 | "compression-webpack-plugin": "^2.0.0", 56 | "cross-env": "^6.0.0", 57 | "css-loader": "^3.0.0", 58 | "enzyme": "^3.8.0", 59 | "enzyme-adapter-react-16": "^1.7.1", 60 | "enzyme-to-json": "^3.3.5", 61 | "file-loader": "^4.0.0", 62 | "html-webpack-plugin": "^3.2.0", 63 | "identity-obj-proxy": "^3.0.0", 64 | "jest": "^24.3.1", 65 | "jest-cli": "^24.3.1", 66 | "jest-watch-typeahead": "^0.3.0", 67 | "mini-css-extract-plugin": "^0.7.0", 68 | "optimize-css-assets-webpack-plugin": "^5.0.1", 69 | "react-test-renderer": "^16.6.3", 70 | "regenerator-runtime": "^0.13.1", 71 | "style-loader": "^0.23.1", 72 | "uglifyjs-webpack-plugin": "^2.0.1", 73 | "webpack": "^4.27.1", 74 | "webpack-bundle-analyzer": "^3.0.3", 75 | "webpack-cli": "^3.1.2", 76 | "webpack-dev-middleware": "^3.4.0", 77 | "webpack-dev-server": "^3.1.10", 78 | "webpack-hot-middleware": "^2.24.3", 79 | "webpack-merge": "^4.1.5", 80 | "webpack-node-externals": "^1.7.2" 81 | }, 82 | "browserslist": [ 83 | "last 1 version", 84 | "> 1%", 85 | "IE 11", 86 | "IE 10", 87 | "IE 9" 88 | ] 89 | } 90 | -------------------------------------------------------------------------------- /01_0_starting.md: -------------------------------------------------------------------------------- 1 | # First steps with React 2 | 3 | ## Trying React online 4 | You can try `React online` through any of the major JS "sandboxes" or "playgrounds". I´m going to use [jsfiddle](https://jsfiddle.net), but, feel free to employ your favorite one. *PS*: Another great service is [codesandbox](https://codesandbox.io/) which allows you to download a compressed file with all the assets and code to run it locally once you are done. 5 | 6 | *Note:* Remember you can also include the path (relative if your are working locally or absolute/CDN) to `React` and `ReactDOM` using the `src attribute of the 13 | 14 | ``` 15 | 16 | **For production:** @16.x.x 17 | ```javascript 18 | 19 | 20 | ``` 21 | 22 | --- 23 | 24 | In your fiddle, if you inspect the output, inside the iframe -> head you will find the 2 libraries plus `Babel`, needed for transpiling `ES* code` (aka, last JS code) into `browser-compatible JS`. 25 | 26 | In *jsfiddle* be sure that you are including `React` and `ReactDOM`. In the `JavaScript input`, under Language, select `Babel + JSX`. 27 | Great! You are ready to start playing! 28 | 29 | Add within the markup or HTML a div with the id `root` (it could be any name). 30 | 31 | ```html 32 |
    33 | ``` 34 | 35 | Inside the JS text-area, place... 36 | ```javascript 37 | function MyFriend() { 38 | return( 39 |
    40 |

    Peter

    41 |
    More...
    42 |
    43 | ) 44 | } 45 | 46 | var app = ( 47 | 48 | ) 49 | 50 | ReactDOM.render( 51 | app, 52 | document.getElementById('root') 53 | ) 54 | ``` 55 | 56 | *The output will be:* 57 | ``` 58 | Peter 59 | More... 60 | ``` 61 | 62 | ... "same" as doing, with `plain JS` ... 63 | 64 | ```javascript 65 | function MyFriend() { 66 | return(` 67 |
    68 |

    Peter

    69 |
    More...
    70 |
    ` 71 | ); 72 | } 73 | 74 | const app = MyFriend(); 75 | const root = document.getElementById('root'); 76 | root.insertAdjacentHTML('beforeend', app) 77 | ``` 78 | 79 | 80 | Don´t worry too much about what´s going on! We will see it in detail during this and the upcoming lessons. For the moment, just remember that you can use `React + ReactDOM` with... 81 | * `