- React Components
- Christopher Pitt
- 242字
- 2021-07-09 19:34:44
Debugging in the browser
We can also use our code directly in the browser. There may be times when we want to see the effects of a change, without a build step. In such cases, we can try something like this:
$ npm install --save babel-core $ npm install --save systemjs
These will give us access to a browser-based dependency manager and cross-compiler; that is, we can use unbundled source code in an example HTML file:
<!DOCTYPE html> <html> <head> <script src="/node_modules/babel-core/browser.js"></script> <script src="/node_modules/systemjs/dist/system.js"></script> </head> <body> <p class="react"></p> <script> System.config({ "transpiler": "babel", "map": { "react": "/examples/react/react", "react-dom": "/examples/react/react-dom", "page": "/src/page" }, "defaultJSExtensions": true }); System.import("main"); </script> </body> </html>
This uses the same unprocessed main.js
file as before, but we no longer need to rebuild it after each change to the source code. The System
is a reference to the SystemJS library we just installed through NPM. It takes care of the import statements, loading those dependencies with Ajax requests.
You may notice the references to react
and react-dom
. We import these in main.js
, but where do they come from? Browserify fetches them out of the node_modules
folder. When we skip the Browserify step, we need to let SystemJS know where to find them.
The easiest place to find these files is at https://facebook.github.io/react. Click on the download button, extract the archive, and copy the JS
files in the build
folder to where they are referenced in the HTML page.
The ReactJS website is a great place to download ReactJS, and find documentation about how you can use it:

- 數(shù)據(jù)庫(kù)系統(tǒng)原理及MySQL應(yīng)用教程(第2版)
- FreeSWITCH 1.6 Cookbook
- Magento 1.8 Development Cookbook
- 人人都是網(wǎng)站分析師:從分析師的視角理解網(wǎng)站和解讀數(shù)據(jù)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲案例實(shí)戰(zhàn)全流程詳解(高級(jí)進(jìn)階篇)
- ExtJS高級(jí)程序設(shè)計(jì)
- JavaCAPS基礎(chǔ)、應(yīng)用與案例
- SQL Server數(shù)據(jù)庫(kù)管理與開發(fā)兵書
- 移動(dòng)互聯(lián)網(wǎng)軟件開發(fā)實(shí)驗(yàn)指導(dǎo)
- UI設(shè)計(jì)全書(全彩)
- Spring Boot+MVC實(shí)戰(zhàn)指南
- JavaScript程序設(shè)計(jì):基礎(chǔ)·PHP·XML
- 一步一步跟我學(xué)Scratch3.0案例
- Penetration Testing with the Bash shell
- Software-Defined Networking with OpenFlow(Second Edition)