推荐关注
› Meteor
› JSLint - a JavaScript code quality tool
› jsFiddle
› D3.js
› WebStorm
推荐书目
› JavaScript 权威指南第 5 版
› Closure: The Definitive Guide
sphawkcn

看官方范例不解,未用到的模块为何要导入?

  •  
  •   sphawkcn · Jul 24, 2016 · 4511 views
    This topic created in 3768 days ago, the information mentioned may be changed or developed.

    正在学习一个 Meteor 的官方范例( https://www.meteor.com/tutorials/react/components ),

    看到这段代码( client/main.jsx ):

    import React from 'react';
    import { Meteor } from 'meteor/meteor';
    import { render } from 'react-dom';
     
    import App from '../imports/ui/App.jsx';
     
    Meteor.startup(() => {
      render(<App />, document.getElementById('render-target'));
    });
    

    这里整段代码中都没有用到 React ,不知为何要用 import React from 'react'; 导入 React ? 小菜鸟理解不了,还请大牛释疑,谢谢。

    2 replies  •  2016-07-24 11:21:20 +08:00
    xxxyyy
    xxxyyy
    Jul 24, 2016 via Android❤️3
    1
    现在看起来好像是没用到 react ,主要是由于实例化 App 这个 react component 使用了 jsx ,但在 js 中 jsx 是不被支持的,因此 jsx 最终需要转化成 js 的代码(一般会通过 babel 来转),这里的 <App /> 会被转成 React.createElement(App),你看,这时需要 React 了吧。
    sphawkcn
    sphawkcn
    OP
    Jul 24, 2016
    2
    @xxxyyy 终于懂了,谢谢指点,自己想破脑袋都想不明白,有指点一下就明白了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3926 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:40 · PVG 17:40 · LAX 01:40 · JFK 04:40
    ♥ Do have faith in what you're doing.