`
sillycat
  • 浏览: 2552358 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

ReactJS(1)Begin from the Starter

    博客分类:
  • UI
 
阅读更多
ReactJS(1)Begin from the Starter

Create the Project to show the diagram for Monitor Job Count
> git clone -o react-starter-kit -b master --single-branch https://github.com/kriasoft/react-starter-kit.git JobCountMonitor

Check ENV
>node --version && npm --version
v6.10.0
3.10.10

> yarn --version
0.20.3

> yarn install
This command will install he dependencies and tools in package.json

> yarn start
This command will build the src to build. It will start Node.js Server (no build/server.js) and Browsersync with HMR.

The outputs are as follow:
http://localhost:3000/      Node.js server (build/server.js)
http://localhost:3000/graphql   - GraphQL server and IDE
http://localhost:3001/      BrowserSync proxy with HMR, React Hot Transform
http://localhost:3002/      BrowserSync control panel (UI)

Start the Project in Release module
> yarn start --release

Build the Project
> yarn run build

Build release Version
> yarn run build -- --release

On my MAC, I did not install docker.
> yarn run build -- --release --docker

Check the Syntax
> yarn run lint

Unit tests with Mocha
> yarn run test

run the tests and watch for changes
> yarn run test:watch
  
Start with ReactJS
https://facebook.github.io/react/docs/installation.html

Introducing JSX - I guess it is JavaScript Extension
const element = <h1>hello</h1>;

Embedding JavaScript expressions in curly braces.

We can try the code online in https://codepen.io/login

A very simple example is as follow:
function formatName(user) {
  return user.firstName + ' ' + user.lastName;
}

const user = {
  firstName: 'Carl',
  lastName: 'Luo'
};

const element = (
  <h1>
    Hello, {formatName(user)}!
  </h1>
);

ReactDOM.render(
  element,
  document.getElementById('root')
);

You should either use quotes(for string values) or curly braces(for expressions), but not both in the same attribute.

JSX Represents Objects
const element = (
    <h1 className=“greeting”>
        Hello
    </h1>
);

the same as

const element = React.createElement(
    ‘h1’,
    {className: ‘greating’},
    ‘Hello'
);

React reads these objects and uses them to construct the DOM.

https://facebook.github.io/react/docs/rendering-elements.html

Upgrade the my nodeJS to latest version
All different versions
https://nodejs.org/en/download/current/

on Mac
>wget https://nodejs.org/dist/v8.0.0/node-v8.0.0.tar.gz
configure and make and make install
>node --version && npm --version
v8.0.0
5.0.0

on CentOS
>wget https://nodejs.org/dist/v8.0.0/node-v8.0.0.tar.gz
Prepare the ENV
>sudo yum install gcc gcc-c++
configure and make and make install
> node --version && npm --version
v8.0.0
5.0.0

on RaspberryPI - Directly Use Binary
I believe my RaspberryPI is arm7
>wget https://nodejs.org/dist/v8.0.0/node-v8.0.0-linux-armv7l.tar.xz
unzip the binary file
>tar xf node-v8.0.0-linux-armv7l.tar.xz
Move it to the working directory
>mv node-v8.0.0-linux-armv7l ~/tool/node-v8.0.0
>sudo ln -s /home/carl/tool/node-v8.0.0 /opt/node-v8.0.0
>sudo ln -s /opt/node-v8.0.0 /opt/node
Add bin to the PATH, check the installation
>node --version
v8.0.0
>npm --version
5.0.0

const element = <h1>Hello</h1>;
unlike browser DOM elements, react elements are plain objects, cheap to create.
React DOM takes care of updating the DOM to match the React elements.

<div id=“root”></div> That is a “root” DOM node. All the thing inside will be managed by React DOM.
to render a React element into a root DOM.
const element = <h1>Hello</h1>;
ReactDOM.render(
    element,
    document.getElementById(‘root');
);

React elements are immutable. Once it is created, we can not change it. An element is like a single frame in a movie.
Updating look and feel will be pass new element to the ReactDOM.render().

Components and Props
function Welcome(props){
    return <h1>Hello, {props.name}</h1>;
}

is as the same as
class Welcome extends React.Component {
    render() {
        return <h1>Hello, {this.props.name}</h1>;
    }
}

Define the element, function and ReactDOM
function Welcome1(props) {
  return <h1>Hello, {props.name}</h1>;
}

const element = <Welcome1 name="Carl" />;
ReactDOM.render(
  element,
  document.getElementById('root')
);

Steps for that, ReactDOM.render() render the element <Welcome1 name=“Carl” />, React call the Welcome1 component with {name:’Carl’} as the props. Welcome1 component returns a <h1>Hello, Carl</h1> element to ReactDOM.

Always start component names with a Capital Letter.
Composing Components
Components can call components.
function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

function App() {
  return (
    <div>
      <Welcome name="Carl" />
      <Welcome name="Kiko" />
      <Welcome name="Leo" />
    </div>
  );
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

Typically, new React apps should have single App component that the very top.


References:
https://github.com/kriasoft/react-starter-kit/blob/master/docs/getting-started.md
https://github.com/kriasoft/react-starter-kit
https://facebook.github.io/react/docs/introducing-jsx.html



分享到:
评论

相关推荐

    vesamenu.c32解决U盘安装centos7卡在press the enter key就不动了

    U盘安装Centos7过程,启动时卡在press the enter key to begin the installation process 就不动弹了。下载附件替换掉/syslinux/vesamenu.c32即可解决。

    Begin to Code with Python

    Understand the social aspects of professional development, and build career-ready skills from the start Whether you’re a total beginner or you’ve tried before, Begin to Code with Python will put the...

    Instant Sublime Text Starter

    With the Sublime Text 2 Starter, you will learn everything you need to know to begin using Sublime Text 2 and some of its more advanced features. This will provide you an excellent start on utilizing ...

    Instant Node.js Starter(英文)

    Node.js is a platform that lets you use JavaScript to easily program scalable network applications and web services....Instant Node.js Starter will begin with installation and your first Hello World ...

    Packt.Python.Journey.from.Novice.to.Expert.2016

    As you complete each one, you'll have gained key skills and get ready for the material in the next module.The first module will begin with exploring all the essentials of Python programming in an ...

    CSmtp_v1_7.rar_Csmtp_The Client_s-box

    -on the server running tcp.exe, another in the same network with the client running on tcplnk.exe require the same port, on the server begin, the client server on the importation of the IP address, ...

    三年级上册英语剑桥Join in版Starter unit Let's begin 单元测试卷.pdf

    三年级上册英语剑桥Join in版Starter unit Let's begin 单元测试卷.pdf

    Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional (1)

    Product Description ...By the time you’ve finished the book, you will have mastered the core techniques and have all the knowledge you need to begin work as a professional ASP.NET developer.

    Neural Networks—Tricks of the Trade (2nd Edition).pdf

    This book is an outgrowth of a 1996 NIPS workshop called Tricks of the Trade whose goal was to begin the process of gathering and documenting these tricks. The interest that the workshop generated, ...

    begin主题包_20170815

    1. **style.css**:这是主题的样式表,定义了布局、颜色、字体等视觉元素。学习者需要理解CSS选择器、盒模型以及响应式设计的概念。 2. **header.php**:包含了页面顶部的内容,如网站标题、导航菜单等。这里会涉及...

    表层进firstly to begin with

    "in addition", "in the first place", "in the past", "last", "lately", "meanwhile", "moreover", "next", "now", "presently", "second", "shortly", "simultaneously" 用于表明事件或想法的时间顺序:"Before ...

    WordPress杂志主题知更鸟Begin最新版LTS版

    《WordPress杂志主题知更鸟Begin最新版LTS详解》 在WordPress的世界里,主题是构建网站外观和用户体验的关键元素。本文将深入探讨“知更鸟Begin”这一热门杂志主题的最新LTS(长期支持)版本,揭示其核心特性和优势...

    The Art of Computer Programming MMIX

    From the Back Cover This multivolume work on the analysis of algorithms has long been recognized as the definitive description of classical computer science. The three complete volumes published to ...

    New-folder-(4).rar_The Common

    We begin with choosing two random large distinct primes p and q. We also pick e, a random integer that is ...From one of the theorems of Euler s, we know that for all integers m, med = m (mod n)

    The 7 Habits of Highly Effective People

    该书的作者Stephen Covey将高度有效的人士的行为模式总结为七个习惯,分别是:Be Proactive、Begin with the End in Mind、Put First Things First、Think Win-Win、Seek First to Understand, Then to be ...

    计算机网络第六版答案

    Because the router has the entire packet at time t1, it can begin to transmit the packet to the receiving host at time t1. At time t2 = t1 + L/R2, the router completes transmission and the entire ...

Global site tag (gtag.js) - Google Analytics