简体   繁体   English

用扩展的React.Component代替React.createClass

[英]Replacing a React.createClass with extends React.Component

Facebook has suggested the future removal of React.createClass completely in favour of ES6 classes. Facebook建议将来完全删除React.createClass,以支持ES6类。 I'm now beginning to go through my react.js classes and replace them with the now accepted class MyClass extends React.Component syntax. 我现在开始浏览我的react.js类,并用现在被接受的class MyClass extends React.Component语法。 However, I don't think I'm quite there yet on some things. 但是,我认为在某些事情上我还没有到位。 I have coded the following API mount and gulp doesn't seem to like this particular module when loading: Cannot find module '.components/ticker-trader' from '/.../src' . 我已经编写了以下API装载代码,并且gulp在装载时似乎并不喜欢该特定模块: Cannot find module '.components/ticker-trader' from '/.../src'

My particular class is outlined as: 我的特殊课程概述为:

import React, { Component, PropTypes } from 'react';

class TickerTrader extends React.Component {
  constructor(props) {
    super(props);
    this.state = {

    };
  }

  componentDidMount() {
      $.get("api_url", function(data) {
        this.setState(data),
      });
  }

  render() {
    return (
      <div></div>
    );
  }
}

export default TickerTrader;

Could anyone outline where exactly this has gone wrong...I'm sure it is something simplisitic. 任何人都可以概述出这到底是哪里出了问题...我确定这是简单的事情。 I have attempted to fix this by using the documentation but I don't seem to be getting anywhere... 我试图通过使用文档来解决此问题,但是我似乎什么也没得到...

Check your file paths. 检查您的文件路径。

Cannot find module '.components/ticker-trader' from '/.../src'

That looks wrong. 看起来错了。

Instead of .components/ticker-trader it more than likely should be looking for ./components/ticker-trader . 除了.components/ticker-trader它更应该寻找./components/ticker-trader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM