More Inside the Classes

React

Shan-Hung Wu & DataLab

CS, NTHU

Separation of Concerns

?

?

?

?

?

HTML: noun

CSS: adjective

JS: verb

Applies well to static pages

But for dynamic content, JS usually ¡°crosses

the line¡±

el.textContent = '...';

2

Modern Frontend Framework

? Write JS in HTML

? Write HTML in JS

3

? Component-based

? Debug-friendly

¨C Syntax errors fails at compile time

¨C Declarative properties make runtime debugging

easy

? Extends to mobile landscape (React Native)

4

$ npm install --save react react-dom

$ npm install --save-dev babel-preset-react

// in webpack.config.js

entry: {

index: './index.jsx',

vendor: ['react', 'react-dom']

}

module: {

rules: [{

test: /\.(js|jsx)$/,

exclude: [/node_modules/],

use: [{

loader: 'babel-loader',

options: {

presets: [

['es2015', {'modules': false}],

'react'

]

}

}]

}], ...

}

Hello React

? *.jsx are JS files with

HTML embedded

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download