zoukankan      html  css  js  c++  java
  • React 是什么

    原文链接:https://www.newline.co/fullstack-react/30-days-of-react/day-1/

    What is React?

    React is a JavaScript library for building user interfaces. It is the view layer for web applications.

    At the heart of all React applications are components.

    A component is a self-contained module that renders some output.We can write interface elements like a button or an input field as a React component.

    Components are composable. A component might include one or more other components in its output.

    Broadly speaking, to write React apps we write React components that correspond to various interface elements. We then organize these components inside higher-level components which define the structure of our application.

    For example, take a form. A form might consist of many interface elements, like input fields, labels, or buttons. Each element inside the form can be written as a React component. We'd then write a higher-level component, the form component itself. The form component would specify the structure of the form and include each of these interface elements inside of it.

    Importantly, each component in a React app abides by strict data management principles.

    Complex, interactive user interfaces often involve complex data and application state. 

    The surface area of React is limited and aimed at giving us the tools to be able to anticipate how our application will look with a given set of circumstances. 

    how do we use it?

    React is a JavaScript framework.

    Using the framework is as simple as including a JavaScript file in our HTML and using the React exports in our application's JavaScript.

    For instance, the Hello world example of a React website can be as simple as:

    <html>
    <head>
      <meta charset="utf-8">
      <title>Hello world</title>
      <!-- Script tags including React -->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js"></script>
      <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    </head>
    <body>
      <div id="app"></div>
      <script type="text/babel">
        ReactDOM.render(
          <h1>Hello world</h1>,
          document.querySelector('#app')
        );
      </script>
    </body>
    </html>
    
     

    Although it might look a little scary, the JavaScript code is a single line that dynamically adds Hello world to the page. Note that we only needed to include a handful of JavaScript files to get everything working.

    How does it work?

    Unlike many of its predecessors, React operates not directly on the browser's Document Object Model (DOM) immediately, but on a virtual DOM

    That is, rather than manipulating the document in a browser after changes to our data (which can be quite slow) it resolves changes on a DOM built and run entirely in memory. After the virtual DOM has been updated, React intelligently determines what changes to make to the actual browser's DOM.

    The React Virtual DOM exists entirely in-memory and is a representation of the web browser's DOM

    Because of this, when we write a React component, we're not writing directly to the DOM, but we're writing a virtual component that React will turn into the DOM.

  • 相关阅读:
    java 查看 class文件编译时使用的编译器版本
    eclipse新建maven工程(web工程)
    U盘插入后电脑提示“使用驱动器F:中的光盘之前需要将其格式化”,该怎么办?(实测有用)
    随笔安装theano的那些故事(亲测有效,附安装包)
    Python学习4Python的交互
    Mysql热备份总结
    php中date()函数的使用
    在linux中用C语言实现ping命令的部分功能
    【转】/etc/sysconfig/目录详解
    python学习(一)
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/12357210.html
Copyright © 2011-2022 走看看